From: Sam Roberts Date: 2003-02-13T13:52:49+09:00 Subject: Re: Why does Array#compact! return the array, but uniq! return a count? Ah. I misread the compact! docs, and thought it was different. Now I understand. Thanks! Sam Quoteing matz@ruby-lang.org, on Thu, Feb 13, 2003 at 01:41:17PM +0900: > Hi, > > In message "Why does Array#compact! return the array, but uniq! return a count?" > on 03/02/13, Sam Roberts writes: > > |I wanted to remove all nils and duplicate values from an array: > | > | ... > | @fields.collect{ |field| field.group }.compact!.uniq! > |end > | > |I wanted to modify in place, because the return value of collect() is > |ephemeral, nobody else can have a reference, no need to duplicate it, I > |thought... > | > |But now I have: > | > | all = @fields.collect{ |field| field.group }.compact! > | all.uniq! > | all > |end > > Array's bang methods return nil if it does not modify the receiver, so > that chaining is not encouraged. > > matz. >