Devin Mullins wrote:
>
> How about:
>
>   [... Hash#each_with_index session ...]

Fine, but see |*a| in Array examples below.
Where would the index go (?)

>
> This, as you already know, doesn't work with Arrays:
> irb(main):027:0> def stuff
> irb(main):028:1>   yield 1,2
> irb(main):029:1> end
> => nil
> irb(main):030:0> stuff {|a| p a}
> (irb):30: warning: multiple values for a block parameter (2 for 1)
>         from (irb):28
> [1, 2]
> => nil
>
> But that's being warned about, so I hope that, in the future, 'a' will
> be set to 1, instead of [1,2]. (...which would make the above trick work
> for Arrays.)

def stuff
  yield [1,2]  # yield one value, let assignment split them.
end

stuff {|a|       p [a]}         #-> [[1, 2]]
stuff {|a, b|    p [a, b]}      #-> [1, 2]
stuff {|a, b, c| p [a, b, c]}   #-> [1, 2, nil]

stuff {|*a|      p [a]}         #-> [[[1, 2]]]
   #-> |*a, index| would look ambiguous, here

>
> It wouldn't provide automatic "with index" functionality, as your hack
> does, but it seems (to me) to be the "cleanest" change to allow you to
> implement _with_index methods without polluting the methods list.
>

I'm sure it would have been desirable in the original #e_w_i
implementation, but difficult, therefore #e_w_i takes exactly
two arguments.


> Sorry if this is a rehash (no pun intended) of stuff covered in the
> ruby-core thread.

No danger ;-)  That was a looong time ago.

>
> Devin
>

daz