On Jul 1, 2011, at 12:55 PM, I=F1aki Baz Castillo wrote:

> 2011/7/1 I=F1aki Baz Castillo <ibc / aliax.net>:
>> I expected that the following could work:
>>=20
>>  array.sort_by{|entry| entry.a or entry.b}
>>=20
>> but it generates:
>>=20
>>   [kk1, kk2, kk3, kk4]
>>=20
>> so obviously it does not work. I'm not very used to =
Enumerable.sort_by
>> method, any tip please?
>=20
> Maybe it would be better to use "class KK" rather than an struct, and
> then define <=3D> method for KK class (and include Enumerable module)?

You can have both:

KK =3D Struct.new(:a, :b) do
  include Enumerable

  def <=3D>
    #...
  end
end

Regards,
Florian=