RosettaCodeData/Task/Associative-array-Iteration/Brat/associative-array-iteration...

17 lines
226 B
Plaintext

h = [ hello: 1 world: 2 :! : 3]
#Iterate over key, value pairs
h.each { k, v |
p "Key: #{k} Value: #{v}"
}
#Iterate over keys
h.each_key { k |
p "Key: #{k}"
}
#Iterate over values
h.each_value { v |
p "Value: #{v}"
}