From: Wayne Scott Date: 2001-05-18T00:40:06+09:00 Subject: [ruby-talk:15329] Re: Pluggable sorting - How would you do it? From: Dave Thomas > The example in http://www.rubycentral.com/book/ref_c_numeric.html#nonzero_qm > shows a slightly more idiomatic form: > > tbl.sort {|a,b| (b[0] <=> a[0].nonzero? || b[1] <=> a[1] } ^^ missing ) here > > This turns out to be exactly the same number of characters as the Perl > version (give or take :) Yes that is a little better. My years of C and Perl cause me to be bitten by the "0 is true" thing occasionally. But it is the right thing for Ruby. > > Of course, if tbl consists of 2 element arrays, you could also just > write > > tbl.sort.reverse Actually in my example it has the first field in reverse order and the second field forward... Thanks, -Wayne