On 3/20/07, Rick DeNatale <rick.denatale / gmail.com> wrote:
>
> It's also not in general easy to come up with a sort_by block which
> does the kind of multi-attribute sort with different sort orders for
> each attribute that the OP was looking for.

I like this hack:

class RevCmp
  attr_reader :this

  def initialize(obj)
    @this = obj
  end

  def <=>(other)
    other.this <=> @this
  end
end

def rev(obj)
  RevCmp.new(obj)
end

a.sort_by {|x| [x.foo, rev(x.bar), x.baz]}

martin