3 ms·
You can call return from inside a proc all you want. You can't do so if you return the proc to an outside scope without getting LocalJumpError. E.g, given:
by vidarh 1y ago
You can call return from inside a proc all you want. You can't do so if you return the proc to an outside scope without getting LocalJumpError.
E.g, given:
def foo = proc do 42 end
def bar = proc do return 42 end
Then `foo.call` is fine, but `bar.call` will indeed give a LocalJumpError as you say.
But a return in a proc that hasn't escaped its defining scope is fine:
def baz = proc do return 42 end.call
Calling `baz` here will just return 42 to the surrounding scope.