output.sort_by {|k, v| v}.reverse
and for keys
h = {\"a\"=>1, \"c\"=>3, \"b\"=>2, \"d\"=>4} => {\"a\"=>1, \"c\"=>3
Try this:
Hash[h.sort_by{ |_, v| -v }]