I was a bit confused too by your example James so I played with it a bit and I think the iteration is calling the equivalent to array[0], array[1], array[2] etc. So It deletes array[0] which is "a", but now array[1] is "c" because you've deleted it rather than set it to nil or whatever and everything has shuffled over.
It's a wild guess but seem logical enough to me. I assume you've got a good reason for not calling array = nil or array = [] David - [email protected] http://davidamcclain.com web design and development On Oct 14, 2009, at 9:22 AM, James Miller wrote: > Hi Everyone, > > Wondering if someone could explain why this doesn't work as (I) > expected... > > array = [ "a", "b", "c" ] > > array.each do |item| > array.delete(item) > end > > array => [ "b" ] > > Why isn't the array empty ( array => [] )? Is there a better > approach? > > Thanks, > James > > > > --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---
