Undefined local variable or method '_FILE_'

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

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

···

from :0
--
Posted via http://www.ruby-forum.com/.

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

-Jeremy

···

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

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..?

Jeremy Bopp 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
--
Posted via http://www.ruby-forum.com/\.