什么时候应该使用lambda或proc?我曾看到它们被描述为匿名函数,但我很难理解这个概念.如果您能在Ruby中,尤其是在Ruby on Rails中,提供任何链接或使用示例,我将不胜感激.
什么时候应该使用lambda或proc?我曾看到它们被描述为匿名函数,但我很难理解这个概念.如果您能在Ruby中,尤其是在Ruby on Rails中,提供任何链接或使用示例,我将不胜感激.
http://augustl.com/blog/2008/procs_blocks_and_anonymous_functions/详细介绍了什么是block/procs/lambda,如何使用它们,以及它们与其他语言中的函数的比较.它肯定回答了你的问题.
Do be aware that the last section 'A note on lambdas' mentions a point that is only true in Ruby 1.8 and changed in 1.9 - Ruby: Proc.new { 'waffles' } vs. proc { 'waffles' }