From: Paul Brannan Date: 2001-07-13T04:37:44+09:00 Subject: [ruby-talk:17745] Re: Array#sort! returns nil when array empty > I'm now thinking that perhaps the "right" way to do this > is: > > foo.gsub('foo','bar').gsub!(' ',"\t") > > i.e., the earlier chained methods are non-bang. > > I'll try this line of thought for a while. > > Hal Well, this does not achieve the desired result: foo = "This is a test" #=> "This is a test" foo.gsub('foo,'bar').gsub!(' ',"\t") #=> "This\tis\tb\ttest" foo #=> "This is a test" What we really want is: foo = "This is a test" #=> "This is a test" foo.gsub!('foo',bar') #=> nil foo.gsub!(' ',"\t") #=> "This\tis\ta\ttest" foo #=> "This\tis\ta\ttest" Paul