Search code examples
rubyreturnblock

How to end execution of a block in Ruby?


I thought blocks were like anonymous functions.

But when I tried to end the execution of a block using return keyword, I think it triggered a return in the scope in which the block was defined in. Is that how they work?

If so, how can I end the execution of a block, in a way that does not trigger a return in the outer scope?


Solution

  • The keyword is next, not break. Break seems to be specific for the each method.