From: Florian Gilcher Date: 2011-07-01T20:23:29+09:00 Subject: Re: How to order Structs based on two fields On Jul 1, 2011, at 12:55 PM, Iņaki Baz Castillo wrote: > 2011/7/1 Iņaki Baz Castillo : >> 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? > > Maybe it would be better to use "class KK" rather than an struct, and > then define <=> method for KK class (and include Enumerable module)? You can have both: KK = Struct.new(:a, :b) do include Enumerable def <=> #... end end Regards, Florian