Ruby - Hashes
What is the output of the following Ruby code?
h = Hash.new { |hash, key| hash[key] = [] }
h[:a] << 1
h[:b] << 2
p hh = Hash.new { |hash, key| hash[key] = [] }
h[:a] << 1
h[:b] << 2
p hh[:a] creates :a => [1]. Similarly, appending 2 to h[:b] creates :b => [2].15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions