【发布时间】:2011-05-23 13:03:15
【问题描述】:
我正在尝试初始化数组的哈希,例如
@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"]
@my_hash["bye"]
=> ["in the street", "at home"]
@my_hash["xxx"]
=> ["in the street", "at home"]
!!!???
我做错了什么初始化数组哈希的正确方法是什么?
【问题讨论】: