From: Timothy Hunter Date: 2007-03-17T07:11:17+09:00 Subject: Re: Issues using array.delete within a loop of the same array james.d.masters@gmail.com wrote: > On Mar 16, 2:01 pm, Timothy Hunter 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>