Forum: Ruby File object. Undefined methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Olivier M. (Guest)
on 2009-05-08 22:49
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
Tim H. (Guest)
on 2009-05-08 23:50
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")
This topic is locked and can not be replied to.