From: Daniel Berger Date: 2005-08-19T03:36:30+09:00 Subject: Re: Idiomatic ruby version of this code? Pit Capitain wrote: > Brock Weaver schrieb: > >> Perfect! Thank you for your quick response. I decided to take the >> shortcut of parallel variable assignment too, so I'm violating my own >> rule a little I guess. > > > Note that all the offered solutions including your original version > don't work if there are two files named "x.mp3" and "x.temp". > > Regards, > Pit > > def switch(old, new) Dir["*.#{old}"].each{ |file| new_name = File.basename(file, old) + "." + new File.rename(file, new_name) unless File.exists?(new_name) } end Regards, Dan