From: Austin Ziegler Date: 2002-11-27T13:45:22+09:00 Subject: Re: each_with_index & collect_with_index? On Wed, 27 Nov 2002 13:32:24 +0900, Jason Persampieri wrote: > _why: >> It would be really cool if, instead of having a million >> *_with_index methods floating around in Enumerable, we had a >> method which could be used inside a block to retrieve the number >> of iterations that the block has undergone. [...] >> This implementation is flawed, though, because it creates the >> `index' method in whatever namespace the block is originally >> placed. But, you know.. what if?? [...] > Why not have a global var (eg $# or something) that keeps the > current index whenever you're iterating through an > array/string/whatever? > > It would be consistent, extremely useful, less confusing and > completely straightforward. > > OK... let the criticism flow! One major problem: global. Globals aren't threadsafe, and by doing a global, I lose any context capabilities for nested indexing. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.11.26 at 23.42.45