Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的应用程序中有类似这样的状态数组
status = ['success','failure','warning']
例如,像这样处理状态数组的 lambda
print_status = lambda { |stat| puts stat }
当我尝试在状态的每个方法上传递 lambda 时,我收到一个错误,上面写着“ArugmentError:参数数量错误(1 代表 0)”
status.each(print_status)
任何人都可以帮助我解决此问题。
此问题是由于块和 proc 不匹配而发生的。在您的状态下,每个方法都需要块而不是 proc。将proc转换为block的理想解决方案是“&”
status.each(&print_status)
希望此代码可以帮助您解决问题