Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > undefined local variable or method '_FILE_'

Reply
Thread Tools

undefined local variable or method '_FILE_'

 
 
Diogo Veras
Guest
Posts: n/a
 
      09-17-2010
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jeremy Bopp
Guest
Posts: n/a
 
      09-17-2010
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..?


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

-Jeremy

 
Reply With Quote
 
 
 
 
Diogo Veras
Guest
Posts: n/a
 
      09-17-2010
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
undefined local variable or method `code_words' for main:Ob Abder-rahman Ali Ruby 3 07-06-2010 11:18 AM
undefined local variable or method 'rsion' for main:Object Steve Meyer Ruby 4 06-26-2008 05:26 PM
undefined local variable or method (filling an array) Thufir Ruby 2 11-10-2007 08:57 PM
Newbie: require 'filename' - undefined local variable or method... Grehom Ruby 10 12-19-2005 08:10 AM
a static local variable in a static method is thread local storage? Patrick Hoffmann C++ 3 08-08-2003 02:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57