Issue #4840 has been updated by Rodrigo Rosenfeld Rosas.


Thanks for the update, but I'd like to point out the description in that document is not accurate:

~~~
### Before
unless cond
  class C
  end
end
# … or …
class C
end unless cond
~~~

This is like the actual code looks like (the one that motivated this feature request):

https://github.com/grjones/gitorious-submodule-dependencies/blob/master/config/initializers/gitorious_config.rb

~~~
unless defined? GitoriousConfig
  GitoriousConfig = c = YAML::load_file(File.join(Rails.root,"config/gitorious.yml"))[RAILS_ENV]

  # make the default be publicly open
  GitoriousConfig["public_mode"] = true if GitoriousConfig["public_mode"].nil?

  # ...
~~~

As you can see, the assumption that we would be dealing with a conditional single class declaration is false, so, the alternative proposal for currently handling this situation does not really apply in several cases.

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-54782

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
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)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


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