UPDATE :
A "top-level return" function has been added .
ORIGINAL :
Commentator Matt noted that the Feature 4840, which will do exactly what I ask, has been discussed since June 2011 . In addition, this feature was still discussed in November 2015 at major group meetings on new Ruby features.
There are many difficulties associated with the development of such a function; For a list of pros and cons, I highly recommend checking out the discussions.
The proposed function will allow you to exit the required file when using any of the following top-level operators:
if condition return end while condition # ... return end begin # ... return rescue # ... return ensure # ... return end
And this will not exit the required file in the following statements:
class Foo return # LocalJumpError end def foo return # returns from method, not from required file end proc do return # LocalJumpError end x = -> { return } # returns as from lambda, not from required file
Since this function remains unfulfilled, I awarded Stinslag a reward for successfully solving the problem (as it was originally written) of the letter, if not the spirit.
user22a6db72d7249
source share