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

K

Kenneth McDonald

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
 
S

Stephen Duncan Jr

[Note: parts of this message were removed to make it a legal post.]

On Wed, Oct 22, 2008 at 11:32 AM, Kenneth McDonald <
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__
 
J

Jesús Gabriel y Galán

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top