Hi --

On Fri, 10 Dec 2004, Gavin Sinclair wrote:

> On Friday, December 10, 2004, 7:24:42 AM, trans. wrote:
>
>> | Small caveat: remember that Array#delete returns the thing deleted,
>> | not the array, so you can't chain it as you would #compact.
>
>> Good catch. Enough reason to have something for it, I think. I may add a
>> general method to my libs:
>
>>   class Array
>>     def compact_on(n=nil)
>>       if n
>>         delete(n)
>>       else
>>         compact
>>       end
>>       self
>>     end
>>   end
>
>> Better name? Or better solution?
>
> Array#compact
>
> It doesn't currently take a parameter, so allow it to take one.  FWIW
> I think Array#delete should be deprecated, and Array#compact extended
> in this fashion.  I don't see a good rationale for the return value of
> Array#delete, and when a method is called #delete there is always
> confusion about whether it's destructive.

I would just as soon have things remain as they are (with the possible
exception of making String#delete destructive; I think it's the only
one that isn't).  But if Matz chooses to revisit this area, I would
not want to see "compact" become a general-purpose method for removing
elements.  [1,2,3,4].compact(3)  just doesn't communicate anything
along the lines of [1,2,4].


David

-- 
David A. Black
dblack / wobblini.net