On 11 Oct 2002, at 10:04, dblack / candle.superlink.net wrote: > (first version snipped) > > or, if you don't have my probably ridiculous aversion to the ternary > operator: > > unsorted = (0...100).map {|t| { :k1 => rand(10), :k2 => t} } > sorted = unsorted.sort do |a,b| > (n = a[:k1] <=> b[:k1]).zero? ? a[:k2] <=> b[:k2] : n > end I'd like to remind you of the nonzero? method: unsorted = (0...100).map {|t| { :k1 => rand(10), :k2 => t} } sorted = unsorted.sort do |a,b| (a[:k1] <=> b[:k1]).nonzero? || a[:k2] <=> b[:k2] end This works in 1.6 too. But if you have Ruby 1.7 and don't need to be compatible to 1.6 I'd use Enumerable#sort_by, as others have shown. Maybe the 1.6 code is a bit more efficient, but I haven't tested this. Regards, Pit