On Mar 20, 2009, at 7:17 AM, Rob Biedenharn wrote: > On Mar 20, 2009, at 3:27 AM, Ryan Davis wrote: >> On Mar 19, 2009, at 20:01 , Rob Biedenharn wrote: >>> On Mar 19, 2009, at 10:44 PM, Ryan Davis wrote: >>>> I'm kinda surprised nobody has said this: >>>> >>>> sorted = matrix.sort_by { |row| [row[0], -row[1]] } >>>> >>> Actually, it was suggested, but it assumes that row[1] has a -@ >>> method. The OP confirmed later that the columns are text, not >>> numbers. >> > > class String > def -@ > self.gsub(/./) {|s| (255 - s[0]).chr } > end > end Oops, it is horrible because it doesn't reverse sort properly: irb> %w( a b c d ).sort_by { |s| -s } => ["d", "c", "b", "a"] irb> %w( a b c d ).sort {|a,b| b <=> a } => ["d", "c", "b", "a"] OK when the ordering is based on a letter mismatch, but when one string is a prefix: irb> %w( a aa ab bb bbb ).sort {|a,b| b <=> a } => ["bbb", "bb", "ab", "aa", "a"] irb> %w( a aa ab bb bbb ).sort_by { |s| -s } => ["bb", "bbb", "a", "ab", "aa"] Perhaps that's one reason there's no String#-@ -Rob Rob Biedenharn http://agileconsultingllc.com Rob / AgileConsultingLLC.com