From: "David A. Black" Date: 2003-12-04T04:09:59+09:00 Subject: Re: each_with_what_index? Hi -- On Thu, 4 Dec 2003, Hugh Sasse Staff Elec Eng wrote: > On Wed, 3 Dec 2003, T. Onoma wrote: > > > > > Saying that there's "absolutely nothing unintutive about that" is a real > > stretch. Obviously, I have asked for certain indexes [1..-1], but we know > > that #[ ] is really just a form of slice, so what we get is a new array, thus > > reindexed form [0..a.length-2]. It's understandable, but I sure wouldn't call > > it intuitive. > > Suppose if each_with_index allowed a range parameter > a.each_with_index(1...a.size) {|t,i|...} > Would that be worth an RCR? It looks sort of natural to me, but... Just for fun: module Enumerable def each_with_index(range=(0...size)) range.each {|i| yield at(i),i} end end though it doesn't do much for me. I guess I haven't seen the problem to which it would be a solution, and it seems to be based on a sort of rollback of the original request (i.e., here's a enumerable; give me its elements and their indices; wait, actually, don't act on the receiver but on a subsequent restraint...). It feels inside-out to me. David -- David A. Black dblack@wobblini.net