From: Robert Dober Date: 2008-08-19T01:39:59+09:00 Subject: Re: Hash#each vs Hash#each_pair 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