Jim Weirich:
This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }
, lambdas are created with lambda {}
and ->() {}
.
In Ruby 1.8, proc {}
creates lambda, and Ruby 1.9 it creates procs (don't ask).
Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.
This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.