matz / zetabits.com (Yukihiro Matsumoto) wrote: [...] >GOTO Kentaro once proposed something like this. > > a = x.sort_by{|x| x.str} > b = x.sort_by{|x| x.int} > c = x.sort_by{|x| x.chr} > >It implements Schwartzian transformation inside. I like this idea, >but am not yet sure "sort_by" is a proper name for the behavior. Hmmm...this doesn't really address my main need in a pluggable sort behaviour. The usual that I want is "this field ascending, that field descending, the next field descending..." Ruby makes it very easy to use a Schwartzian sort with the first few elements being the fields I want, all ascending. But to reverse specific fields is another kettle of fish. BTW I just tried what I think should work in Ruby 1.6.2 but it didn't seem to work. I must be forgetting something obvious...? class StringReverse < String def <=> (other) -1 * super(other) end end p [StringReverse.new("hello"), StringReverse.new("world")].sort Cheers, Ben