我试图初始化一个数组的哈希表,例如:
@my_hash = Hash.new(Array.new)
以便我能够:
@my_hash["hello"].push("in the street")
=> ["in the street"]
@my_hash["hello"].push("at home")
=> ["in the street", "at home"]
@my_hash["hello"]
=>["in the street", "at home"]
问题在于任何新的哈希键也会返回["in the street", "at home"]
。
The problem is that any new hash key also return ["in the street", "at home"]
@my_hash["bye"]
=> ["in the street", "at home"]
@my_hash["xxx"]
=> ["in the street", "at home"]
我做错了什么,初始化Hash of Arrays的正确方法是什么?