undefined local variable or method '_FILE_'

D

Diogo Veras

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
 
J

Jeremy Bopp

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

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

-Jeremy
 
D

Diogo Veras

Jeremy said:
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
 

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

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top