# File object. Undefined methods

**URL:** <https://www.ruby-forum.com/t/file-object-undefined-methods/167515>\
**Category:** Ruby\
**Created:** [May 8, 2009, 8:49pm UTC](https://www.ruby-forum.com/t/file-object-undefined-methods/167515 "2009-05-08T20:49:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kojilab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kojilab](https://www.ruby-forum.com/u/kojilab)\
**Post date:** [May 8, 2009, 8:49pm UTC](https://www.ruby-forum.com/t/file-object-undefined-methods/167515/1 "2009-05-08T20:49:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kojilab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kojilab](https://www.ruby-forum.com/u/kojilab)\
**Post date:** [May 8, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/file-object-undefined-methods/167515/2 "2009-05-08T21:50:48Z")

</div>

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")
