From: Mark Hubbart Date: 2004-11-10T07:30:34+09:00 Subject: Re: Iterating trough hash On Wed, 10 Nov 2004 05:23:39 +0900, ara.t.howard@noaa.gov wrote: > On Wed, 10 Nov 2004, Mark Hubbart wrote: > > > > >> if h.sort.index([person1,h[person1]]) < h.sort.index([person2,h[person2]]) > >> > >> says: > >> > >> if the name of person1 is less than the name of person2 OR the names are the > >> SAME but the age of person1 is less than the age of person2. > > > > Um, no, I think this says: > > > > if the index of the first element that matches [person1, age1] is > > greater than the > > index of the first element that matches [person2, age2]. > > consider the meaning of the h.sort and how ruby will do it by default. > > h.sort => array of key value pairs sorted first on name then on age > > h.sort.index => look for the natural ordering of an entry where the > ordering has been defined by ruby's Array#sort method > > you are correct in what you said - but what does that __mean__? you are, of course, correct -- I overlooked the big picture. I was pointing out that [person,age] were the correct arguments for that method, but you were pointing out that there was a more appropriate method that could be used. Sorry for the needless contradiction :) > so - why do you think the OP included age in the search? what was the code > trying to say? Just a guess, but perhaps they didn't think to use the #keys method. I didn't automatically think of it when I saw this code. But only the OP can actually answer the question fully :) cheers, Mark > > kind regards. > > > > -a > -- > =============================================================================== > | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov > | PHONE :: 303.497.6469 > | When you do something, you should burn yourself completely, like a good > | bonfire, leaving no trace of yourself. --Shunryu Suzuki > =============================================================================== > >