From: Robert Klemme Date: 2011-07-01T21:12:23+09:00 Subject: Re: How to order Structs based on two fields On Fri, Jul 1, 2011 at 1:22 PM, Iņaki Baz Castillo wrote: > 2011/7/1 Robert Klemme : >> array.sort_by {|e| [e.a, e.b]} > > Note that entries must be ordered by smaller :a and, in case of same > :a, by higher :b. So the last "e.b" should be changed to something > else. Trying it right now. Oh, my mistake. I am sorry. So that would be (for numeric b): array.sort_by {|e| [e.a, -e.b]} And then KK = Struct.new :a,:b do include Comparable def <=>(o) cmp = a <=> o.a cmp == 0 ? o.b <=> b : cmp end end Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/