Skip to content

Instantly share code, notes, and snippets.

@chicks-net
Created April 18, 2018 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chicks-net/72eccc05c1b69a3ddee7b145bec8bc51 to your computer and use it in GitHub Desktop.
Save chicks-net/72eccc05c1b69a3ddee7b145bec8bc51 to your computer and use it in GitHub Desktop.
#!/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