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).

if the time is just the UNIX time can't you negate it too?  can use 
to_f  first.

and then to negate a string probably is too expensive...  using 255 to 
subtract its ASCII value or XOR each character with 0xFF.

how about just use sort {|x, y| [y.name, x.time] <=> [x.name, y.time] }
so now the name is "negated".
-- 
Posted via http://www.ruby-forum.com/.