undefined local variable or method '_FILE_'

Discussion in 'Ruby' started by Diogo Veras, Sep 17, 2010.

  1. Diogo Veras

    Diogo Veras Guest

    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/.
     
    Diogo Veras, Sep 17, 2010
    #1
    1. Advertising

  2. Diogo Veras

    Jeremy Bopp Guest

    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
     
    Jeremy Bopp, Sep 17, 2010
    #2
    1. Advertising

  3. Diogo Veras

    Diogo Veras Guest

    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/.
     
    Diogo Veras, Sep 17, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Hoffmann
    Replies:
    3
    Views:
    2,841
    Christian Jan├čen
    Aug 8, 2003
  2. Grehom
    Replies:
    10
    Views:
    383
    Grehom
    Dec 19, 2005
  3. Thufir
    Replies:
    2
    Views:
    162
    Thufir
    Nov 10, 2007
  4. Steve Meyer
    Replies:
    4
    Views:
    279
    Steve Meyer
    Jun 26, 2008
  5. Abder-rahman Ali
    Replies:
    3
    Views:
    135
    Abder-rahman Ali
    Jul 6, 2010
Loading...

Share This Page