From the nature of the question, I assume this is for ruby 1.9.
p Hash[hsh.sort_by{|k, v| v[0]}]
# => {"c1"=>[11, 33], "c9"=>[23, 7], "c2"=>[44, 2]}
p Hash[hsh.sort_by{|k, v| v[1]}]
# => {"c2"=>[44, 2], "c9"=>[23, 7], "c1"=>[11, 33]}
sawa source
share