----- Original Message -----
From: "Harry Ohlsen" <harryo / qiqsolutions.com>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Tuesday, August 05, 2003 8:17 PM
Subject: Re: What's New and Shiny in Ruby 1.8.0?


> Something that's not mentioned, but I figured I'd try it, because I
thought it would be nifty, is sorting by multiple values ...
>
>   text = ["the", "quick", "brown", "fox", "jumps", "over", "the", "lazy",
"dog"]
>
>   puts text.sort_by { |x| [x.length, x] }.inspect
>
>   #=> ["dog", "fox", "the", "the", "lazy", "over", "brown", "jumps",
"quick"]
>
> Ie, we now have the values sorted first by their length, and when the
length is the same, they're sub-sorted by the text itself.  I think that's
great!
>
> This would be particularly useful if the data items in the enumeration
were instances of more complex objects. Then, you could do things like:
>
>    sorted = people.sort_by { |p| [p.last_name, p.first_name, p.salary] }
>
> I just love Ruby!

Agreed. I'll file the multi-key sort under T for Things That
Make Me Go Ahhh...

Hal

--
Hal Fulton
hal9000 / hypermetrics.com