Forum: Ruby Sanity check on File.dirname

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.
Daniel B. (Guest)
on 2009-02-10 22:06
(Received via mailing list)
Hi,

I need a quick sanity check.

Excepting potential backslashes for the moment, aren't these two
identical?

File.dirname(path).split('/')[0..-2].join('/')

File.dirname(File.dirname(path))

Dan
Pit C. (Guest)
on 2009-02-11 11:24
(Received via mailing list)
Dan, they differ if the path isn't nested deeply enough, for example
"/a/b", "/c" or "d".

Regards,
Pit
This topic is locked and can not be replied to.