From: Alexey Verkhovsky Date: 2004-07-18T08:12:23+09:00 Subject: Re: [NUBY] Ruby Way code for shuffling an array doesn't behave as expected On Sun, 2004-07-18 at 01:43, Mark Sparshatt wrote: > It's because the block passed to collect is changing the contents of a, > so it doesn't reach all the elements of a. So, Ruby iterators operate on the original collection and let you modify the collection in the process. Another fact useful to remember. This is, by the way, one thing I like about Java iterators: they are fail-safe in such scenarios. E.g. List list = new ArrayList(2); list.add(new Object()); list.add(new Object()); Iterator i = list.iterator(); i.next(); // this is OK list.add(new Object()); // list gets changed i.next(); // throws ConcurrentModificationException IMHO, an exception here is The Right Thing (TM). At least, it saved me from my own stupid mistakes more than once. Best regards, Alex