35

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?

1

2 Answers 2

57

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

Sign up to request clarification or add additional context in comments.

Comments

-10

To exit a block or loop use the break keyword.

return will exit a method.

1 Comment

break from proc-closure (LocalJumpError)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.