From: "David A. Black" Date: 2004-09-21T10:56:51+09:00 Subject: Re: Array#index block and rdetect Hi -- On Tue, 21 Sep 2004, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Array#index block and rdetect" > on Tue, 21 Sep 2004 01:23:07 +0900, "David A. Black" writes: > > |> This (numerical index) is what I thought when I designed > |> each_with_index. So I vote for introducing a new name. > | > |I liked Tom's idea of "counter". That seems to be more what it is. > > Sorry for being noisy. Feel free :-) > Do you mean we should rename each_with_index to each_with_counter? In > that case, do you have any estimation about compatibility? Here's one possibility. I don't think this would be bad for compatibility, because Array would have its *_index methods, and I don't think #each_with_index is used much (ever?) for anything except arrays and maybe array subclasses. Enumerable: each_with_counter # "dumb" counters, for every enumerable, each_counter # strictly based on incrementing through # #each Array: each_with_index # either very similar to, or identical to, each_index # the *_counter methods (because that # happens to be how arrays work). Hash and other enumerable classes: In addition to the *_counter methods, each enumerable class can have its own, "smart" methods (just as Array does with its *_index methods). They can have "index" in the name, if appropriate -- but they do not have to. (There are no Enumerable#*_index methods.) In other words: keep the dumbest, most general behavior in Enumerable, and let the various enumerable classes keep/override/add to, etc., that behavior. David -- David A. Black dblack@wobblini.net