From: Gabriel Dragffy Date: 2007-08-23T20:47:21+09:00 Subject: Re: Renaming Files On 23 Aug 2007, at 12:27, Peter Hickman wrote: > The problem here is the ! on the gsub. This is changing the > contents of f *before* it gets passed to the function: > > def show(a, b) > puts "[#{a}] [#{b}]" > end > > x = "Here is a string" > > show(x, x.gsub!(/\s/,'_')) > > results in > > [Here_is_a_string] [Here_is_a_string] > > But change the gsub! to a plain gsub and you get > > [Here is a string] [Here_is_a_string] > > because a plain gsub returns a copy of the modified string without > modifying the original. > > Only use the ! versions when you are absolutely sure you need to. > > Thank you so much for these replies (Peter & Stefano). That makes perfect sense. As soon as you pointed out gsub! was doing what is was supposed to :) Thanks. I just renamed a directory of about 30 files in 0.5 seconds with that one. Just another quicky, if I wanna rename all the files in the directory is what I did OK, using: next if f=="." or f==".." I just feel there must a better way? Best regards Gabriel