From: Martin DeMello Date: 2005-10-26T20:07:03+09:00 Subject: Re: sort on multiple attributes Terje Tjervaag wrote: > > Say you have an array of these music tracks: > Track = Struct.new("Track", :name, :artist, :album, :track_number) > > .and you want to sort the array first by artist, then by album within > that artist and finally by track number within the album, this can > still be done by a pretty neat sort block: tracklist.sort_by {|i| [i.artist, i.album, i.track_number] } works because ruby already defines Array#<=> to check the first entry, break ties on the second entry, etc. martin