Created
September 14, 2013 06:42
-
-
Save devmug/6559401 to your computer and use it in GitHub Desktop.
sorting and iterating a hash in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flash.each do |key, value| | |
puts "#{key}" | |
puts "#{value}" | |
end | |
Calling sort on a hash converts it into nested arrays and then sorts them by key, so all you need is this: | |
puts h.sort.map {|k,v| ["#{k}----"] + v} | |
puts h.sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment