My input hash: h = { \"a\" => 20, \"b\" => 30, \"c\" => 10 }
h = { \"a\" => 20, \"b\" => 30, \"c\" => 10 }
Ascending sort: h.sort {|a,b| a[1]<=>b[1]} #=> [[\"c\", 10], [\"a
h.sort {|a,b| a[1]<=>b[1]} #=> [[\"c\", 10], [\"a
<=> compares the two operands, returning -1 if the first is lower, 0 if they're equal and 1 if the first is higher. This means that you can just do -(a[1]<=>b[1]) to reverse the order.
<=>
-(a[1]<=>b[1])