ruby sort hash by value

lets say you have a hash
hh = {1=>'y', 2=>'a'}
if you need to sort a hash by its value this works like this
Hash[hh.sort_by{|k, v| v}]

in case your hash looks like this
hh = {1=>'y',2=>'A'}
you should be aware to change your value to lower case like this
Hash[hh.sort_by{|k, v| v.downcase}]

in case your hash looks like this
hh = {1=>0.0,2=>nil,3=>4.0}
you need to replace nil with a sortable value
hh.sort_by{|k, v| v ? v : 0}