From: Eric Hodel Date: 2006-05-26T07:15:42+09:00 Subject: Re: Array#delete_if! - a method to delete and return all array items for which the block evaluates to true. On May 25, 2006, at 3:03 PM, Alder Green wrote: > Here's a method to delete and return all items in an Array for which > the block evaluates to true: [...] > Would people suggest better implementations? The obvious problem here > is that we're duplicating arr (to_delete and to_keep contatin together > a cloned arr). I came up with an index based solution to avoid that, > but frankly it was quite ugly. $ ri Array#reject! ---------------------------------------------------------- Array#reject! array.reject! {|item| block } -> array or nil ------------------------------------------------------------------------ Equivalent to +Array#delete_if+, deleting elements from _self_ for which the block evaluates to true, but returns +nil+ if no changes were made. Also see +Enumerable#reject+. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com