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.
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (djberg96)
on 2009-02-10 21: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
50b2daf0e7666574579b9edaf8f2b69a?d=identicon&s=25 Pit Capitain (Guest)
on 2009-02-11 10: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.