# What is Ruby equivalent of Python's ' if \_\_name\_\_ == "\_\_main\_\_" '

**URL:** <https://www.ruby-forum.com/t/what-is-ruby-equivalent-of-pythons-if-name-main/151539>\
**Category:** Ruby\
**Created:** [October 22, 2008, 5:34pm UTC](https://www.ruby-forum.com/t/what-is-ruby-equivalent-of-pythons-if-name-main/151539 "2008-10-22T17:34:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 22, 2008, 5:34pm UTC](https://www.ruby-forum.com/t/what-is-ruby-equivalent-of-pythons-if-name-main/151539/1 "2008-10-22T17:34:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 22, 2008, 5:44pm UTC](https://www.ruby-forum.com/t/what-is-ruby-equivalent-of-pythons-if-name-main/151539/2 "2008-10-22T17:44:50Z")

</div>

On Wed, Oct 22, 2008 at 11:32 AM, Kenneth McDonald \<  
removed\_email\_address@domain.invalid\> 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**

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 22, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/what-is-ruby-equivalent-of-pythons-if-name-main/151539/3 "2008-10-22T17:46:36Z")

</div>

On Wed, Oct 22, 2008 at 5:32 PM, Kenneth McDonald  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
