From: "David A. Black" Date: 2008-07-27T06:59:01+09:00 Subject: Re: head/tail split for path Hi -- On Sun, 27 Jul 2008, Thomas Sawyer wrote: > Hi David, > > David A. Black wrote: >> >> Check out the Pathname feature: >> >> require 'pathname' >> >> p = Pathname.new("a/b/c") >> >> You get p.basename and p.dirname. Both return Pathname objects, but >> they're quite string-like and easily converted. > > p = Pathname.new("a/b/c") > > p.dirname #=> "a/b" > p.basename #=> "c" > > But I need "a" and "b/c". Whoops. Well, you could do: require 'enumerator' [path.to_enum(:ascend).to_a[1], path.basename] or something like: path.scan(/([^\/]+)\/(.*)/) # with the String path Pathname#cleanpath might come in handy if you're rolling your own. So might File::Separator. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails July 21-24 Edison, NJ * Advancing With Rails August 18-21 Edison, NJ * Co-taught by D.A. Black and Erik Kastner See http://www.rubypal.com for details and updates!