From: "David A. Black" Date: 2004-09-20T11:12:12+09:00 Subject: Re: Array#index block and rdetect Hi -- On Mon, 20 Sep 2004, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Array#index block and rdetect" > on Mon, 20 Sep 2004 10:19:46 +0900, "David A. Black" writes: > > |> In that case, Hash#each and Enumerable#each_with_index should be > |> redefined for consistency. > | > |Could #each_with_index be left to individual classes, as #each_index > |is? > > Can you express your idea in detail? > > * Enumerable#each_index should be removed (yes/no) There is no Enumerable#each_index -- nothing to remove. > * Array#each_with_index should be added (yes/no) Yes. (Florian's ideas about merging #each and #each_with_index is also interesting, though I'm not sure it would be good to always have an "extra" parameter passed to the block.) > * Hash#each_with_index should be added with key as index (yes/no) No. The key is already available to block, with #each. (But you said Hash#each would be redefined -- I'm not sure what that would involve.) > * How about other enumerable classes? I think the idea of every enumerable class having an "index", defined as part of that class, is possibly useful. For hashes it could be the keys; for arrays, the integer index; for files, the line number. In some cases (like index/key for hashes), it might be redundant. But it might open up some good possibilities. That would mean an enumerable class would have to be able to say: "This is how I define 'index'." I'm not sure how that would work. David -- David A. Black dblack@wobblini.net