From: Robert Dober Date: 2006-08-19T17:02:41+09:00 Subject: Re: how does sort work on hash ------=_Part_17070_6009519.1155974560138 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 8/19/06, hemant kumar wrote: > > > I am just a little curious about how exactly sort workes on hashes. > > for example: > a =3D {:foo =3D> 10,:bar =3D> 5,:duh =3D> 20} > > a.sort {|x,y| y[1] <=3D> x[1]} x and y represent the key, value pairs of the hash and therefore you sort b= y values, descending order... now how exactly the above line works.the block is passed two elements at a > time, as array? If yes, how sort treates the next two elements? ... there are no *next two elements* the block just tells ruby how to compare any two key, value pairs. Ruby than applies a sorting algorithm internally... what algorithm this sort is based on? Is it inplace sorting? or only sort! does inplace sorting? An array is created from the hash which is sorted by quicksort with the criteria indicated above May be the question is not so much about hashes. Exactly, the question is about Enumerations. Hope that helps Robert --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_17070_6009519.1155974560138--