From: Ryan Davis Date: 2009-03-20T16:27:52+09:00 Subject: Re: Complex sort of matrix possible, e.g. like Excel? 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