Issue #4824 has been updated by Lazaridis Ilias.


Nobuyoshi Nakada wrote:
> Hi,
>  
>  At Wed, 8 Jun 2011 16:44:55 +0900,
>  Charles Oliver Nutter wrote in [ruby-core:36833]:
>  > I might be more inclined to a keyword or pseudo constant along the
>  > lines of __FILE__, like __MAIN__ that produces true iff __FILE__ ==
>  > $0. Something we can statically determine before runtime without
>  > digging around in the caller's frame.

@C.O. Nutter
I you dislike "digging around in the caller's frame", then you can possibly implement it in a different way.

>  __FILE__.main?

This is not an OO approach, even I would prefer to use "if __FILE__ == $0" instead.

I would expect to see __FILE__.main? in python, not in ruby.

There is already an object available, accessible via "self".

main? # read: is main?
 # do main stuff
end

or

self.main? # read: self is main?
 # do main stuff
end

in some way, self refers to the file or code module/object.



----------------------------------------
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