On Tue, Jun 7, 2011 at 7:33 PM, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> Ah, I understand the request. But returning from outside of a method
> makes me so weird.

I agree with both the feature and the fact that return outside a
method feels weird. An early termination of a loading file would be
welcome; I've wanted this many times, and always ended up doing the
super-gross "giant if" to accomplish what could be done by a simple
early exit.

I wonder if a core method that does the early return would be a better
option, like Kernel#exit_script. It could be implemented to throw an
exception all requires and loads expect to catch, like
"ExitScriptError" or something. That would seem more consistent than
having return end the script...but not actually be returning anything.

Another option would be to use a different keyword that isn't so tied
to method/proc bodies, like "break"

break if defined? GitoriousConfig

I think I like the exit_script version better, though.

exit_script if defined? GitoriousConfig

- Charlie