From: Marko Schulz Date: 2001-12-23T06:48:45+09:00 Subject: [ruby-talk:29323] Re: upper case to lower On Sat, Dec 22, 2001 at 05:20:02PM +0900, nobu.nokada@softhome.net wrote: > > Thanks to explain. > > At Sat, 22 Dec 2001 15:55:12 +0900, > HarryO wrote: > > >> Dir.entries(X).each do |f| > > >> (n = f.dup).downcase! and File.rename(File.join(X, f), File.join(X, > > >> n)) > > >> end > > >> > > > okey I don't understand the "!" part why do u have it > > > > In Ruby, methods that modify an object, as opposed to returning > > a new version of an object with the requested change, tend to > > end with '!'. > > And it uses the fact that String#downcase! returns nil if no > change occurred, to rename only files which contain upper > cases. It is code like that, that is giving Perl a bad reputation. It works, but it does not communicate what it does. IMNSHO the code posted by Joseph McDonald is much better (after replacing the String#tr with String#downcase). I wish this wouldn't be(come) custom in Rubyland. -- marko schulz