When should a lambda or proc be used? I have seen them described as anonymous functions, but I am struggling to understand this concept. I would appreciate any links to or examples of when you might use one in Ruby, but especially in Ruby on Rails.
Share
http://augustl.com/blog/2008/procs_blocks_and_anonymous_functions/ has a run-down of what blocks/procs/lambdas are, how you can use them, and how they compare to functions in other languages. It definitely answers your question.
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' }