From: Rob Biedenharn Date: 2009-03-20T20:17:51+09:00 Subject: Re: Complex sort of matrix possible, e.g. like Excel? 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]] } >>> >>> P.S. PLEASE trim to the relevant parts when you reply. In some of >>> your email on this thread you have two whole copies of nearly the >>> whole thread. >> >> Actually, it was suggested, but it assumes that row[1] has a -@ >> method. The OP confirmed later that the columns are text, not >> numbers. > > kk. sorry. I made assumptions based on him using Matrix. I couldn't > see that someone suggested this already through all the noise. :) > > umm.... > > class String > def -@ > self.gsub(/./) { |s| (?z - s[0] + ?a).chr } > end > end > > >> %w(abc def ghi jhk).sort_by { |s| -s } > => ["jhk", "ghi", "def", "abc"] > > horrible, no? > > :D Only if you have any characters that aren't lowercase letters. class String def -@ self.gsub(/./) {|s| (255 - s[0]).chr } end end Well, still pretty horrible, though. irb> - "Ryan Davis" => "\255\206\236\221\337\273\236\211\226\214" If you ever meet someone with that name, don't shake hands; the universe could come to an end! -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com