sorting - Sort hash by key, return hash in Ruby -


would best way sort hash , return hash object (instead of array):

h = {"a"=>1, "c"=>3, "b"=>2, "d"=>4} # => {"a"=>1, "c"=>3, "b"=>2, "d"=>4}  hash[h.sort] # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4} 

in ruby 2.1 simple:

h.sort.to_h 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -