On Sun, 14 Oct 2007 21:27:53 +0900, mortee wrote:

> Hello,
> 
> is it possible to reverse order when using a Time as sort key for
> sort_by?
> 
> I know I could use sort, and time2 <=> time1, but it's getting
> complicated when the sort key is compound, like
> 
> sort_by{|e| [e.name, e.time]}
> 
> With e.g. numerics I can simply negate the value for reverse order, but
> I can't negate a Time (or a String, for that matter).
> 
> thx
> mortee

The integer solutions others have given are more elegant, but just for 
completeness...

I believe sort_by implements a stable sort, meaning it doesn't change the 
order of equivalent elements, so you could sort

sort_by{|e| e.time}.reverse.sort_by{|e| e.name}

--Ken

-- 
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/