On Fri, Jul 1, 2011 at 1:22 PM, I=F1aki Baz Castillo <ibc / aliax.net> wrote:
> 2011/7/1 Robert Klemme <shortcutter / googlemail.com>:
>> 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 =3D Struct.new :a,:b do
 include Comparable

 def <=3D>(o)
   cmp =3D a <=3D> o.a
   cmp =3D=3D 0 ? o.b <=3D> b : cmp
 end
end


Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/