output.sort_by {|k, v| v}.reverse
and for keys
h = {\"a\"=>1, \"c\"=>3, \"b\"=>2, \"d\"=>4} => {\"a\"=>1, \"c\"=>3
Try:
Hash[h.sort.reverse]
This should return what you want.
Edit:
To do it by value:
Hash[h.sort_by{|k, v| v}.reverse]