From: Jan Svitok Date: 2007-01-09T23:53:13+09:00 Subject: Re: sortung a structured array on more than one criteria On 1/9/07, Josselin wrote: > On 2007-01-09 15:29:43 +0100, Josselin said: > > > I can sort an array like that : > > > > results = rs.sort_by{|p| p.km} > > > > but I tried to add a scrond sorting criteria like that : > > > > results = rs.sort_by{|p| p.km, p.updated_at } > > > > and I got obviously an error ... parse error, unexpected '}', > > expecting tCOLON2 or '[' or '.' > > > > canot find the correct writing.. > > > > appreciate any help... > > > > thanks > > > > joss > > thanks to both of you... and HNY%2007 (Dry version of Happy New Year > 2007) ;-)) > > I forgot to ask about a DESC sort.... p.km is Ascending and > p.updated_at should be DESC.. > > I am not sure that is possible (at least not documented.....) > > joss results = rs.sort_by{|p| p.km, -p.updated_at } # if updated_at is Numeric or results = rs.sort { |a,b| [a.km, b.updated_at] <=> [b.km, a.updated_at] }