From: tragomaskhalos Date: 2008-04-24T20:10:04+09:00 Subject: Re: Question about array.each{|x| delete x} On Apr 24, 10:04 am, Frisco Del Rosario wrote: > myArray = [1, 2, 3] > > puts myArray > > myArray.each {|x|   > if x == 1 >   then puts "one" >   elsif x == 2 >     then >     myArray.delete x >   elsif x == 3 >     then puts "three" >   end   >   } > > puts myArray > > The output of the above is: > 1 > 2 > 3 > one > 1 > 3 > > And my question is "why isn't it 1 2 3 one three 1 3?". What if I wanted > to make it so? I just dup, like this: myArray.dup.each {|x| ... delete from (original) myArray in here .... } I'm sure there are more elegant solutions, and it's a bit pants from a performance perspective for large arrays, but it works for me.