Read it
new (obj) → new_hash
If specified obj, this single object will be used for all default values.
Hash.new(Array.new)- on this line you created the default array object. Which will be returned whenever you want to access a key that does not exist inside the hash.
h['a'].push('apple') - / , . h['a'] , Array.new, Array#push, all.Thus h['a'] . puts h {}, 'a' .
. :
h = Hash.new(Array.new)
h.default
h['a'].push('apple')
h.default
:
h['a'] = 'Bob'
h['a']
h
h['b']
Hash#[]
Reference - , . , ( . Hash::new).