In Ruby 1.8 (my version is 1.8.7-72), this code:
foo = lambda do
for j in 1..2
return
end
end
foo.call
crashes with a LocalJumpError
:
test2.rb:3: unexpected return (LocalJumpError)
from test2.rb:2:in `each'
from test2.rb:2
from test2.rb:6:in `call'
from test2.rb:6
Why does it do this? However, it seems to run fine on my version of Ruby 1.9.
Edit: it's not just the returning inside a lambda; the following runs fine:
foo = lambda do
return
end
foo.call