Would this be the best way to sort a hash and return Hash object (instead of Array):
h = {\"a\"=>1, \"c\"=>3, \"b\"=>2, \"d\"=>4} # => {\"a\"=
You gave the best answer to yourself in the OP: Hash[h.sort] If you crave for more possibilities, here is in-place modification of the original hash to make it sorted:
Hash[h.sort]
h.keys.sort.each { |k| h[k] = h.delete k }