I was always under the impression that return inside a block was undefined behavior. Can you use next instead?

For instance, Rubinius also has this problem but is much more explicit:

[1].map(&lambda { |n| return -1 }) LocalJumpError: unexpected return

Of course, using next produces the expected results:

rbx-head :003 > [1].map(&lambda { |n| next -1 }) => [-1]

The moral of the story is that return is defined for methods, and Procs and lambdas are not methods. next and break are the keywords to use if you wish to stop a block call.

I can't find any documentation about return 's behavior from the official Ruby spec, but rubyspec does have tests that verify return causes the calling method to return.

https://github.com/rubyspec/rubyspec/blob/master/language/return_spec.rb#L184