From: google@... (Tom Payne) Date: 2003-02-13T20:08:33+09:00 Subject: Re: Why does Array#compact! return the array, but uniq! return a count? matz@ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1045109926.846613.10554.nullmailer@picachu.netlab.jp>... > Array's bang methods return nil if it does not modify the receiver, so > that chaining is not encouraged. I'm not suggesting a change, but what is the rationale for this? IMHO, chaining is one of the most useful aspects of ruby -- multiple lines of code can be folded into one. With chaining you're generally not interested in the intermediate results (otherwise you'd store them in a variable somewhere) and so in-place modification is more efficient since you don't have to create lots of intermediate objects that are then immediately discarded. If you do want to chain, but don't want to modify the receiver, then you can just insert an Object#dup. uniq!, for example, actually does two things: it removes duplicates from the receiver AND tells you whether the were any duplicates in the original array. IMHO these should be separate methods. Therefore I think that the scheme that desctructive updates (! methods) should always return self, i.e. that Ruby's behaviour is wrong. Obviously you've thought about this in detail so what am I missing? Once again, I'm not suggesting a change (it would break just about every Ruby program!), but am interested in Matz's original reasoning. Cheers, Tom