Ruby: difference between proc and lambda

A proc and a lambda are very similar except:

1. they handle arguments differently

proc {} 

and {}

are equivalent.

However, using lambda {} gives you a proc that checks the number of arguments passed to it.



2. they handle return and break statements differently

def bar 

f = lambda { return “from inside lambda”}

return “return from bar”


puts bar

def foo

f = { return “from inside proc”}

return “return from foo”


puts foo


return from bar

from inside proc



Note that the behaviour of proc and lambda changed between Ruby 1.8 and Ruby 1.9 (and therefore 2.0). 

In 1.8, they were identical (both had lambda semantics). 

proc was like lambda in 1.8. However, it’s like in 1.9

See also this post which summarises the difference as follows:

“In short: lambdas behave like methods, non-lambda Procs behave like blocks.”


Leave a Reply

Your email address will not be published. Required fields are marked *