Complete the code to get all keys from the hash.
my_hash = {a: 1, b: 2, c: 3}
keys = my_hash.[1]
puts keysThe keys method returns an array of all keys in the hash.
Complete the code to get all values from the hash.
my_hash = {x: 10, y: 20, z: 30}
vals = my_hash.[1]
puts valsThe values method returns an array of all values in the hash.
Fix the error in the code to print each key and value pair.
my_hash = {name: 'Alice', age: 30}
my_hash.[1] do |key, value|
puts "#{key}: #{value}"
endThe each method iterates over each key-value pair in the hash.
Fill both blanks to create a hash of word lengths for words longer than 3 letters.
words = ['cat', 'house', 'tree', 'a', 'dog'] lengths = {} words.each do |word| if word.length [2] 3 lengths[word] = word[1] end end puts lengths
Use .length to get the length of each word and > to filter words longer than 3 letters.
Fill all three blanks to create a hash with uppercase keys and values greater than 10.
data = {"a": 5, "b": 15, "c": 25}
result = {}
data.[3] do |k, v|
if v > 10
result[[1]] = [2]
end
end
puts resultUse each to iterate, k.upcase for uppercase keys, and v for values.
