I am using ruby ââ1.8.7.
p = lambda { return 10;}
def lab(block)
puts 'before'
puts block.call
puts 'after'
end
lab p
The code above is displayed
before
10
after
I reorganized the same code into this
def lab(&block)
puts 'before'
puts block.call
puts 'after'
end
lab { return 10; }
Now I get LocalJumpError: unexpected return.
Both codes do the same for me. Yes, in the first case, I pass proc, and in the second case, I pass the block. But the block will convert the block to proc. Therefore, proc.call should behave the same.
And yes, I saw this post Using 'return' in a Ruby Block
source
share