# If \_\_FILE\_\_ == $0 & ruby & rdebug & FXRuby

**URL:** <https://www.ruby-forum.com/t/if-file-0-ruby-rdebug-fxruby/191704>\
**Category:** Ruby\
**Created:** [July 16, 2010, 2:28pm UTC](https://www.ruby-forum.com/t/if-file-0-ruby-rdebug-fxruby/191704 "2010-07-16T14:28:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [July 16, 2010, 2:28pm UTC](https://www.ruby-forum.com/t/if-file-0-ruby-rdebug-fxruby/191704/1 "2010-07-16T14:28:19Z")

</div>

The following line acts differently under rdebug and ruby  
if **FILE** == $0

FXRuby has the line, above, in nearly all its sample code.

Under rdebug, the value of $0 is, on my system,  
F:/InstantRails-2.0-win/ruby/bin/rdebug

Executing  
ruby -rdebug UltraDedup.rb  
then the value of $0 is  
Debug.rb

Executing  
ruby UltraDedup.rb  
then the value of $0 is  
UltraDededup.rb

How can I change things so that  
if **FILE** == $0  
acts correctly in each environment?

Ralph

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [July 16, 2010, 10:00pm UTC](https://www.ruby-forum.com/t/if-file-0-ruby-rdebug-fxruby/191704/2 "2010-07-16T22:00:18Z")

</div>

$0 = The program you are running from the command line.

AKA you are running rdebug therefore $0 ==  
F:/InstantRails-2.0-win/ruby/bin/rdebug

Enter irb and console:

MANISH:jes [07-16 09:01] 0 501:1 (14.43 Mb) • ~  
! irb

irb(main):001:0\> $0  
=\> “irb”

Make sense?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [July 16, 2010, 6:30pm UTC](https://www.ruby-forum.com/t/if-file-0-ruby-rdebug-fxruby/191704/3 "2010-07-16T18:30:09Z")

</div>

On 7/16/10, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The following line acts differently under rdebug and ruby  
> if **FILE** == $0

The name rdebug is ambiguous. Do you mean debug.rb, the debugger which  
comes with ruby, or the ruby-debug gem? I suspect it’s the latter,  
since I have encountered this same bug with it.

> Executing  
> ruby UltraDedup.rb  
> then the value of $0 is  
> UltraDededup.rb

This is an unfortunate bug in ruby-debug. In general, ruby-debug has  
more problems for me than debug.rb, so I usually jsut use debug.rb.  
The reason to prefer ruby-debug is because it’s so much faster.  
Sometimes, this becomes very important.

> How can I change things so that  
> if **FILE** == $0  
> acts correctly in each environment?

I know of no really good solution. Typically, I manually set $0 to  
**FILE** at the beginning of a debugging session to work around this  
problem (cursing all the while). I think this command is guaranteed to  
do it:

p $0= **FILE**

Tho with some versions of ruby-debug, I could leave off the p.
