Hi,
In message "Hashes and Enumerable#each_with_index"
on 03/04/25, Ryan Pavlik <rpav / nwlink.com> writes:
|The problem: Hash#each_with_index returns an index that is not usable
|to address the hash. That is, given the following:
|
| h = Hash.new
| h.each_with_index {
| | o, i |
| ...
| }
|
|i is not defined such that h[i] == o, which is both misleading and
|seemingly useless. (This behavior, as per the previous discussion, can
|be achieved with h.to_a.each_with_index.)
|
|Would it not be more useful to adopt the definiton of
|Enumerable#each_with_index where the index given is such that e[i] == o
|for any given Enumerable?
No. Index in each_with_index means offset of the values. It might be
possible to implement a method that you described for arrays, hashes,
string, etc. But it should have different name.
matz.