From: Robert Klemme Date: 2009-03-18T19:16:34+09:00 Subject: Re: Complex sort of matrix possible, e.g. like Excel? 2009/3/18 Christopher Dicely : > Enumerable#sort lets you do this fairly easily with just a pure array > of arrays, e.g., to sort the array-of-arrays "arr" by the first column > ascending and the second descending: > > arr.sort {|a,b| [a[0]<=>b[0], b[1]<=>a[1]].find {|x| x!=0} || 0} Alternatively with less intermediate Arrays and less comparison operations. arr.sort do |a,b| c = a[0]<=>b[0] c == 0 ? b[1]<=>a[1] : c end You can as well do arr.sort_by {|a,b| [a[0]<=>b[0], b[1]<=>a[1]]} Cheers robert -- remember.guy do |as, often| as.you_can - without end