# Undefined local variable or method '\_FILE\_'

**URL:** <https://www.ruby-forum.com/t/undefined-local-variable-or-method-file/195111>\
**Category:** Ruby\
**Created:** [September 17, 2010, 5:58am UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-file/195111 "2010-09-17T05:58:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![metanolbr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@metanolbr](https://www.ruby-forum.com/u/metanolbr)\
**Post date:** [September 17, 2010, 5:58am UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-file/195111/1 "2010-09-17T05:58:12Z")

</div>

Hi all,

Don’t know why but when I try to use the _FILE_ variable I’m getting the  
following error:

irb(main):001:0\> puts File.dirname(_FILE_)  
NameError: undefined local variable or method `_FILE_’ for main:Object  
from (irb):1  
from :0

I’ve got this error in Windows Seven and Ubuntu 10.04 LTS, both using  
Ruby 1.8.7

Have also tried running the code in .rb file but get the same error.  
Neither File.dirname(_FILE_) nor only _FILE_ seems to work.

Looked about it everywhere but got nothing. Any idea…?

Regards,

metanolbr

---

<div class="post-metadata">

**Author:** ![metanolbr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@metanolbr](https://www.ruby-forum.com/u/metanolbr)\
**Post date:** [September 17, 2010, 6:03am UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-file/195111/2 "2010-09-17T06:03:27Z")

</div>

On 09/16/2010 10:59 PM, Diogo Veras wrote:

> I’ve got this error in Windows Seven and Ubuntu 10.04 LTS, both using  
> Ruby 1.8.7
> 
> Have also tried running the code in .rb file but get the same error.  
> Neither File.dirname(_FILE_) nor only _FILE_ seems to work.
> 
> Looked about it everywhere but got nothing. Any idea…?

You need to use **FILE** (note the 2 underscores on each side).

-Jeremy

---

<div class="post-metadata">

**Author:** ![metanolbr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@metanolbr](https://www.ruby-forum.com/u/metanolbr)\
**Post date:** [September 17, 2010, 6:09am UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-file/195111/3 "2010-09-17T06:09:18Z")

</div>

Jeremy B. wrote:

> On 09/16/2010 10:59 PM, Diogo Veras wrote:
> 
> > I’ve got this error in Windows Seven and Ubuntu 10.04 LTS, both using  
> > Ruby 1.8.7
> > 
> > Have also tried running the code in .rb file but get the same error.  
> > Neither File.dirname(_FILE_) nor only _FILE_ seems to work.
> > 
> > Looked about it everywhere but got nothing. Any idea…?
> 
> You need to use **FILE** (note the 2 underscores on each side).
> 
> -Jeremy

It worked. Can’t believe, you are right, have no idea how I let this  
pass.

Thank you a lot.

Regards
