File object. Undefined methods

Discussion in 'Ruby' started by Olivier Moratin, May 8, 2009.

  1. Hi

    I'm doing the following in the console of a Rails app

    >> file = File.open("#{RAILS_ROOT}/xml/feed.xml")

    => #<File:/WebApps/app/xml/feed.xml>
    >> f.dirname

    NoMethodError: undefined method `dirname' for
    #<File:/WebApps/app/xml/feed.xml>

    I've tried other methods written in the doc of the File class to no
    avail.

    What am I missing?

    Thanks
    --
    Posted via http://www.ruby-forum.com/.
    Olivier Moratin, May 8, 2009
    #1
    1. Advertising

  2. Olivier Moratin

    Tim Hunter Guest

    Olivier Moratin wrote:
    > Hi
    >
    > I'm doing the following in the console of a Rails app
    >
    >>> file = File.open("#{RAILS_ROOT}/xml/feed.xml")

    > => #<File:/WebApps/app/xml/feed.xml>
    >>> f.dirname

    > NoMethodError: undefined method `dirname' for
    > #<File:/WebApps/app/xml/feed.xml>
    >
    > I've tried other methods written in the doc of the File class to no
    > avail.
    >
    > What am I missing?
    >
    > Thanks


    Read the doc very carefully. dirname is a singleton method in File, not
    an instance method.

    File.dirname("#{RAILS_ROOT}/xml/feed.xml")
    --
    Posted via http://www.ruby-forum.com/.
    Tim Hunter, May 8, 2009
    #2
    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. Mantorok Redgormor
    Replies:
    70
    Views:
    1,724
    Dan Pop
    Feb 17, 2004
  2. Nikita Petrov
    Replies:
    2
    Views:
    103
    Gary Wright
    Apr 6, 2008
  3. Kenneth McDonald
    Replies:
    5
    Views:
    299
    Kenneth McDonald
    Sep 26, 2008
  4. VK
    Replies:
    45
    Views:
    577
    Dr John Stockton
    Sep 12, 2006
  5. -Lost
    Replies:
    13
    Views:
    357
    Richard Cornford
    Jan 31, 2007
Loading...

Share This Page