On Fri, Jul 1, 2011 at 4:22 PM, Iñáki 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/