On Fri, Jul 1, 2011 at 4:22 PM, Iki Baz Castillo <ibc / aliax.net> wrote:
> Hi, I've a struct like this:
>
>  >
> and some entries in an array:
>
>  뱽ˮ> <struct KK a=0, b=10>
>
>  벽ˮ
> struct KK a=0, b=5>
>
>  볽ˮ
> <struct KK a=2, b=0>
>
>   ˮ> <struct KK a=2, b=5>
>
>   벬 뱬 
>
>
> 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:
>
>  뱬 벬 봬 
>
>
> I expected that the following could work:
>
>    

How about:

array.sort do |i, j|
  r = i.a <=> j.a
  case r
    when 0 r
    else  -1 * (i.b <=> j.b)
  end
end


-- 
Anurag Priyam
http://about.me/yeban/