Sort Hash

h={'c' => 3, 'a' => 1, 'b' => 2 }
h.sort_by { |k,v| -v }
h.sort_by { |k,v| v }

# Result:
irb(main):039:0> h={'c' => 3, 'a' => 1, 'b' => 2 }
=> {"c"=>3, "a"=>1, "b"=>2}
irb(main):040:0> h.sort_by { |k,v| -v }
=> [["c", 3], ["b", 2], ["a", 1]]
irb(main):041:0> h.sort_by { |k,v| v }
=> [["a", 1], ["b", 2], ["c", 3]]




h={"abc"=>{"a"=>1, "b"=>1, "c"=>1}, "def"=>{"d"=>1, "e"=>1, "f"=>1}, "csv"=>{"c"=>1, "s"=>1, "v"=>1}}

h.each_with_object({}) { |(k, v),obj| obj[k] = v.values.sum }.sort_by { |k,v| -v }