Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ruby Hash iteration with index
months = { January: 31, February: 28, March: 31, April: 30, May: 31, June: 30, July: 31, August: 31, September: 30, October: 31, November: 30, December: 31 }
months.each_with_index do |(key, val), i|
puts "#{i}: #{key} has #{val} days"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment