Issue #4840 has been updated by mame (Yusuke Endoh).


Rodrigo Rosenfeld Rosas,

At the developer meeting (7/21), Matz was basically positive
to this proposal, but it turned out that we still need to
discuss corner cases.


Here is a discussion summary.

* Matz said that he will accept "return from toplevel", but
  that reject "return from class definition".

  return if cond # OK
  class Foo
    return if cond # NG
  end

* "return from toplevel" should always discard the argument.

* What's happen if it returns from the start script (the given
  script to interpreter as a cmdline)?

  - The argument should be discarded; it does NOT affect the
    process termination status code

  - The same as "exit", but cannot rescue SystemExit

* What's happen in the following corner cases?

  - eval("return") in toplevel

  - proc { return }.call in toplevel

* Matz prefered "return" to "a special exception that require
  and load rescue",

  - though some people (including ko1) prefered the latter.

-- 
Yusuke Endoh <mame / tsg.ne.jp>
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-28309

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/