Issue #4824 has been updated by Tsuyoshi Sawada.


Close to Nobu's proposal `FILE.main?`, but I don't think it makes sense to introduce two new things `FILE` and `main?` that can only be used under this combination. I propose defining a method on the existing `File` class. Something along:

    File.main?
    File.from_here?

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

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

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

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

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

or

main() if executed?

This addition would not break any existent behaviour.




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