Je suis en train d'initialiser une table de hachage de tableaux tels queComment puis-je initialiser un tableau dans une table de hachage en Ruby
@my_hash = Hash.new(Array.new)
afin que je puisse:
@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"]
Le problème est que toute nouvelle clé de hachage également retourner ["in the street", "at home"]
@my_hash["bye"]
=> ["in the street", "at home"]
@my_hash["xxx"]
=> ["in the street", "at home"]
!!! ??? Qu'est-ce que je fais de mal quelle serait la bonne façon d'initialiser un Hash of Arrays?
connexes: http://stackoverflow.com/questions/190740/setting-ruby-hash-default-to-a-list – tokland