From: Austin Ziegler Date: 2003-08-30T02:07:22+09:00 Subject: Re: #collect with block modifying receiver On Fri, 29 Aug 2003 22:02:01 +0900, Dan North wrote: > So it's undefined behaviour, but "Don't modify the receiver while you are > iterating over it." :) > > Can I suggest the solution that Java uses, which is to fail fast in that > situation (ConcurrentModificationException). You would not believe how > much debugging time that one tiny feature has saved me! I wouldn't like that, personally. I don't remember exactly where, but I believe that I have a piece of code taking advantage of the fact that a receiver *can* be modified during iteration. I don't modify during a #collect, but during an #each. One of the things you can do is: arr.each { |e| arr << f.flatten if f.kind_of?(Array) } -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.08.29 * 13.04.26