On Monday 20 September 2004 09:56 pm, David A. Black wrote:
> On Tue, 21 Sep 2004, Yukihiro Matsumoto wrote:
> > 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.)

If I may add to this. In addition to the above, Hash would have:

	each_with_index {|value,key| ...

And then all other Enumerable classes, would have 'each_with_index' defined 
specifically for them to do the same as they do now, but with a warning, 
"#each_with_index will change to #each_with_counter. Change now to ensure 
future compatibility." Or something like that.

No big deal so far b/c very few programs use each_with_index for anything but 
Array.

The larger compatibility issue would come from Hash#each being changed to 
return only value and not key. This is a bigger change, but has advantages 
b/c then hash and array can be better used interchangeably, e.g.

  a = [1,2,3]
  h = {:a=>1,:b=>2,:c=>3}

  def show_succ(x)
    x.each {|v| puts v.succ}
  end

  show_succ(a)
  show_succ(h)

Would work, but now it doesn't:

  NoMethodError: undefined method `succ' for [:b, 2]:Array

T.

-- 
( o _  елеще┴
 //    trans.
/ \    transami / runbox.com

I don't give a damn for a man that can only spell a word one way.
-Mark Twain