Skip to content

Instantly share code, notes, and snippets.

@devmug
Created September 14, 2013 06:42
Show Gist options
  • Save devmug/6559401 to your computer and use it in GitHub Desktop.
Save devmug/6559401 to your computer and use it in GitHub Desktop.
sorting and iterating a hash in ruby
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