On 5/3/07, Pe, Botp <botp / delmonte-phil.com> wrote:
> from: Josselin [mailto:josselin / wanadoo.fr] :
> #  anArray.sort {|a,b| a[1] <=> b[1]}
> # sorts only on first value... how can I sort on both.. ?
>
> try sort_by
>
> irb(main):020:0> a=[["a", 3, 3], ["c", 1, 5], ["b", 1, 2],["d",3,1]]
> => [["a", 3, 3], ["c", 1, 5], ["b", 1, 2], ["d", 3, 1]]
> irb(main):021:0> a.sort_by {|x| [x[1],x[2]]}
> => [["b", 1, 2], ["c", 1, 5], ["d", 3, 1], ["a", 3, 3]]
>
>
>

Or this :)

p anArray.sort_by {|x| [x[1],x[2],x[0]]}

Harry

-- 
http://www.kakueki.com/ruby/list.html
A Look into Japanese Ruby List in English