On Wed, Nov 27, 2002 at 01:49:10PM +0900, dblack / candle.superlink.net wrote:
> So a new global of that kind probably isn't on the horizon.  I was
> playing around with extending objects during iteration, so that you
> could do:
> 
>   ary.map {|e| puts "We're at iteration #{e.iteration}"}
> 
> or something -- but I haven't come up with a way to do it that
> fits more than a subset of cases.  For one thing, you can't
> extend Fixnums, so anything based on that method won't work if
> your array contains those.  Also, the syntax of block parameters
> makes it hard:  if you have
> 
>   ary.map {|e,f,g| ... }
> 
> I'm not sure there's a way to determine which object got the
> #iteration method added to it....

Well, how about something like Regexp.last_match, where you can
make a call to retrieve the iteration data.

ary.map { |e,f,g|
  ei = Enumerable.iteration_info
  #...
}
-- 
Alan Chen
Digikata Computing
http://digikata.com