On Oct 13, 2010, at 02:08 , Y. NOBUOKA wrote:

> The one way to do a reverse sort is wrapping a sort target in a class
> for a reverse sort.
> For instance:
>=20
> # This class is a class for a reverse sort.
> # An Object of various datatypes can be wrapped in an object of this =
class.
> class ItemForReverseSort
>  def initialize( item )
>    @item =3D item
>  end
>  def item
>    @item
>  end
>  def <=3D>( target )
>    ( self.item <=3D> target.item ) * (-1)
>  end
> end

I like this, but think it is more complex than it needs to be.

module ReverseSort
  def <=3D> target
    -super
  end
end

class Object
  def -@
    self.dup.extend ReverseSort
  end
end

b =3D [ ["radio", 30, 5], ["radio", 20, 5], ["archie", 20, 5], =
["newton", 10, 3] ]

p b.sort_by{|x| [ x[1], -x[0] ]}
# =3D> [["newton", 10, 3], ["radio", 20, 5], ["archie", 20, 5], =
["radio", 30, 5]]