Issue #4824 has been updated by Lazaridis Ilias.
The sentence "defines" essentially the terminology:
Yukihiro Matsumoto wrote:
> I agree providing a method to tell whether it is loaded as a library or
^^^^^^^^^
"is loaded"
loaded?
> is executed as a command
^^^^^^^^^^^
"is executed"
executed?
> is more elegant than '__FILE__ == $0', but I am still afraid #executed? can mean multiple ways so that the name can cause confusion. We need a better name.
Thus the question to focus on is:
* is "executed?" not clear enough?
If not, possibly just "loaded?" can be introduced.
main() unless loaded?
----------------------------------------
Feature #4824: Provide method Kernel#executed?
http://redmine.ruby-lang.org/issues/4824
Author: Lazaridis Ilias
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
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.
--
http://redmine.ruby-lang.org