Reputation: 11
Suppose I have a hash, {"c": 1, "b": 2, "a": 3} How do I sort the hash so the elements are in order of the key value?
Upvotes: 0
Views: 424
Reputation: 5
myh = {"c" => 1, "b" => 2, "a" => 3}
myh.sort
=> [["a", 3], ["b", 2], ["c", 1]]
Upvotes: 1