Last Updated: February 25, 2016
·
467
· ryooo321

Ruby hash key sort

sorted_map = {}
# asc
unsorted_map.sort.each {|key, val| sorted_map[key] = val}
# desc
# unsorted_map.sort.reverse.each {|key, val| sorted_map[key] = val}