Forum: Ruby What is Ruby equivalent of Python's ' if __name__ == "__main__" '

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
47df9cfb356c3ee0523cc3571b169730?d=identicon&s=25 Kenneth McDonald (Guest)
on 2008-10-22 17:34
(Received via mailing list)
In Python, I can use the test indicated in the subject line to
determine if a file is being executed directly, as opposed to being
loaded indirectly as the result of the execution of another file. I
haven't been able to find the Ruby equivalent of this, and would be
most grateful is someone could point me in the right direction.

Thanks,
Ken McDonald
8dbdbce510486cd57d20f8aadd727528?d=identicon&s=25 Stephen Duncan Jr (Guest)
on 2008-10-22 17:44
(Received via mailing list)
On Wed, Oct 22, 2008 at 11:32 AM, Kenneth McDonald <
kenneth.m.mcdonald@sbcglobal.net> wrote:

> In Python, I can use the test indicated in the subject line to determine if
> a file is being executed directly, as opposed to being loaded indirectly as
> the result of the execution of another file. I haven't been able to find the
> Ruby equivalent of this, and would be most grateful is someone could point
> me in the right direction.
>
> Thanks,
> Ken McDonald
>

if $PROGRAM_NAME == __FILE__
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 Jesús Gabriel y Galán (Guest)
on 2008-10-22 17:46
(Received via mailing list)
On Wed, Oct 22, 2008 at 5:32 PM, Kenneth McDonald
<kenneth.m.mcdonald@sbcglobal.net> wrote:
> In Python, I can use the test indicated in the subject line to determine if
> a file is being executed directly, as opposed to being loaded indirectly as
> the result of the execution of another file. I haven't been able to find the
> Ruby equivalent of this, and would be most grateful is someone could point
> me in the right direction.

if __FILE__ == $0

end


Jesus.
This topic is locked and can not be replied to.