From: Nikolai Weibull Date: 2007-11-16T07:24:05+09:00 Subject: Re: Thoughts about Array#compact!, Array#flatten!, Array#reject!, String#strip!, String#capitalize!, String#gsub!, etc. On Nov 15, 2007 8:14 PM, Wolfgang N�dasi-Donner wrote: > The methods listed in the header return "nil" when nothing was done. This may be > usefull and used in several situations. > > Unfortunately there is possible usage of these methods, when this return value > is a very bad thing: In a method-chain like... > > "I am a 20MB string".downcase.split(/\s+/).reject{|s|s.length>20} > > In this case the initial string, the result of "downcase", and of "split" will > only be used once - they are single threaded. If, as the example text will name, > the original String object is about 20MB, "downcase" will produce a copy, which > will be thrown away. The same is true for "reject". It would be much better to > use... > > "I am a 20MB string".downcase!.split(/\s+/).reject!{|s|s.length>20} > > ...but this is not possible, because "downcase!" and "reject!" will return "nil" > if they have nothing to do. Your problem isn't the return value of downcase!. Your problem is a String, 20MB in size.