From: reuben doetsch Date: 2008-08-19T01:48:47+09:00 Subject: Re: Hash#each vs Hash#each_pair ------=_Part_148556_30024466.1219078326640 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I think it would make sense to add the alias each_value to array for each since he is correct in that for an array the key is just a integer, and the value is just the array element, so in a sense there should be a each_value for array. I could add this to the Ruby core and submit, if anyone thinks it is a good idea. On Mon, Aug 18, 2008 at 12:39 PM, Robert Dober wrote: > On Mon, Aug 18, 2008 at 6:08 PM, Patrick Doyle wrote: > > But I realized (immediately) that Hash#each didn't do the same > > thing as Array#each. > You are making a statement here that I consider extremely unfair, how > can Hash#each do the same than Array#each. > Turned out the behavior of Hash#each was not suiting your abstraction > and you conclude that it is not doing the same? Pardon me if I am > upset, well I am not, but I could be right... ;). > > > > With that long winded setup... here is the next question I promised > you... > > > > What do other folks do in this situation? > > > > Are you all just smarter/more experienced with Ruby/ than I am and > > have learned (perhaps through bitter experience) that storing things > > in a Hash is better than storing them in an array when you are just > > prototyping some code, not knowing where it will eventually lead? Do > > you all know of the secret Array#each_element iterator which does the > > same thing as the Hash#each_element iterator and you just use that > > > > > On a related note... > > Would it make sense to propose adding an Array#each_value, aliased to > > Array#each to the baseline language/library definition so that one > > could use the same iterator independent of whether the underlying > > container were a Hash or an Array? > Well maybe we were not quite clear enough, the above proposal is not > feasible, iterating over a hash cannot behave like iterating over an > array. > > Would it make sense to propose > > adding an #each_element iterator to both classes? > No it would not. > > > > --wpd > > > > > > Robert > > ------=_Part_148556_30024466.1219078326640--