From: Peter Hickman Date: 2007-08-23T20:27:10+09:00 Subject: Re: Renaming Files 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.