From: "Iñaki Baz Castillo" Date: 2011-07-01T19:52:59+09:00 Subject: How to order Structs based on two fields Hi, I've a struct like this: KK = Struct.new(:a,:b) and some entries in an array: kk1=KK.new(0,10) # kk2=KK.new(0,5) kk3=KK.new(2,0) # kk4 = KK.new(2,5) # array = [kk3, kk2, kk1, kk4] I need to order the array based: - Elements with minor :a must be first. - If two elements have same :a, then order based on higher :b. The result should be: [kk1, kk2, kk4, kk3] I expected that the following could work: array.sort_by{|entry| entry.a or entry.b} but it generates: [kk1, kk2, kk3, kk4] so obviously it does not work. I'm not very used to Enumerable.sort_by method, any tip please? Thanks a lot. -- Iñaki Baz Castillo