From: why the lucky stiff Date: 2005-08-19T03:46:20+09:00 Subject: Re: Idiomatic ruby version of this code? Daniel Berger wrote: > gsub and backreferences? Why take that approach when File.basename is > available? > > def switch(old, new) > Dir["*.#{old}"].each{ |file| > new_name = File.basename(file, old) + "." + new > File.rename(file, new_name) > } > end You understand he's trying to swap extensions, right? (I think?) Well, you've got to get the extension name. And File.extname( file )[1..-1] is ugly. I always go for short and dirty. I steal second base! _why