Created
April 18, 2018 17:50
-
-
Save chicks-net/72eccc05c1b69a3ddee7b145bec8bc51 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# define hash | |
hash = { | |
"k1" => "v1", | |
"k2" => ["v2","v3","v4"], | |
"k3" => ["v5"], | |
} | |
puts hash | |
# print key/value pairs | |
hash.each do |key, value| | |
if value.kind_of?(Array) | |
value.each { |inner_value| puts "#{key}:#{inner_value}" } | |
else # not an array | |
puts "#{key}:#{value}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment