Issue #4824 has been updated by Charles Nutter.


The "main" toplevel object already gets special methods, so why not just define main.main? Avoid polluting Kernel or creating a special class for __FILE__ just to support a "main" feature.

----------------------------------------
Feature #4824: Provide method Kernel#executed?
https://bugs.ruby-lang.org/issues/4824#change-51227

* Author: Lazaridis Ilias
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
The current construct to execute main code looks not very elegant:

~~~ruby
if __FILE__ == $0
  my_main()          # call any method or execute any code
end
~~~

With a `Kernel#executed?` method, this would become more elegant:

~~~ruby
if executed?
  #do this
  #do that
  my_main()
end
~~~

or

~~~ruby
main() if executed?
~~~

This addition would not break any existent behaviour.




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