On Mon, 1 Jun 2009 03:35:47 +0900
Ian Duggan <ian / ianduggan.net> wrote:

> On Sun, May 31, 2009 at 1:52 AM, Martin DeMello
> <martindemello / gmail.com> wrote:
> > File.extname ought to have a complementary method that gets
> > everything but the extension. Useful for scripts that need to
> > mangle a filename
> 
> Is this too much? I admit I find all the File.* ugly to type every
> time I have to do it. It seems verbose.
> 
> irb --> fn = "/a/b/c/d.e"
>     ==> "/a/b/c/d.e"
> 
> irb --> File.join(File.dirname(fn), File.basename(fn,
> File.extname(fn))) ==> "/a/b/c/d"

require 'pathname'

fn = Pathname('/a/b/c/d.e')
# #<Pathname:/a/b/c/d.e>

fn.dirname + fn.basename('.*')
# #<Pathname:/a/b/c/d>


--  
^ manveru