----- Original Message ----- From: <dblack / candle.superlink.net> To: "ruby-talk ML" <ruby-talk / ruby-lang.org> Sent: Wednesday, November 27, 2002 6:50 AM Subject: Re: each_with_index & collect_with_index? [snippage] > which assigns the inner array elements to e and f. Now, somewhere > behind the scenes (in my version), you're adding the #iteration method > to the actual objects being iterated. But here, the object -- the > inner array -- doesn't actually appear as itself in the block; it's > split across two variables. So you can't say "e.iteration" or > "f.iteration", because the original [e,f] array (["one","two"]) is the > object that responds to "iteration". David, Adding singletons to the iterator variable was a path that I went down once... it had some drawbacks, e.g., no Fixnums and overhead of adding a singleton to *each object*. Now that you've been playing with this some, what are your thoughts on my "super-iterator" from a few months back? One of the problems it tried to solve was subsuming #each_with_index into #each by making every iterator object a special object with an accessor method; if the value changed, it would be stored back in the original collection. Someone will (correctly) protest that this doesn't replace every usage of #each_with_index. But (personally) my most common use of it is when I need to replace or change an element in an array while I'm iterating. Hal