On Apr 19, 2009, at 1:17 PM, Yoann Guillot wrote: > My code walks an array, and may change the current element, which is > allowed without breaking the iteration. > > I have also a special case where i have to change a whole subsection > of the array, this was the case where i used 'retry' > > eg > ary.each { |e| > case e > when foo > ary[ary.index(e)] = foo(e) > when bar > when ... > when baz > ary[ary.index(e), 12] = [flublu] > retry > end > } > > Sure, i could use map or many other ways, my code is quite ugly > anyway. Yeah, for a case like this, I would probably just resort to tracking an index in a variable and using a boring while loop. 90% of the time it's wrong to track your own index in Ruby, but I think you're squarely in the special 10% here. Really, you should already be using each_with_index() above because your repeated calls to index() are inefficient for big data sets (rewalking possibly large portions of the Array) and they break if the data set contains duplicate entries. Plus, I'm just not comfortable relying on the iterators to do the right thing while I edit the collection out from underneath them. Obviously it was working for you, but I'm not confident enough to trust it under all cases. > I don't see the point in removing capabilities from the language > (restarting an iteration from within), but I can sure live with it. It was done because retry had some nasty side effects and was causing performance issues: http://markmail.org/message/laisvqelyjmgh56p#query:ruby%20core%20retry %20remove+page:1+mid:fxoxlphjdndatp4m+state:results James Edward Gray II