Tim Hunter
3/16/2007 10:11:00 PM
james.d.masters@gmail.com wrote:
> On Mar 16, 2:01 pm, Timothy Hunter <TimHun...@nc.rr.com> wrote:
>
>> Use #delete_if instead.
>>
>
> Thanks - I tried that and it also did not work. Sorry for not posting
> this attempt in my original:
>
> irb(main):001:0> a = [1,2,3,4,5]
> => [1, 2, 3, 4, 5]
> irb(main):002:0> a.each {|e| a.delete_if {|e2| e2 == e}}
> => [2, 4]
>
>
>
#delete_if itself iterates over the array elements. You don't need to
use #each at all.
$ irb
irb(main):001:0> a = [0,1,2,3,4,5]
=> [0, 1, 2, 3, 4, 5]
irb(main):002:0> a.delete_if {|e| e %2 == 0}
=> [1, 3, 5]
irb(main):003:0>