如何使用已具有值的键在Hash对象中附加值.所以举个例子
如果我有
如果我有
>> my_hash = Hash.new >> my_hash[:my_key] = "Value1" # then append a value,lets say "Value2" to my hash,using that same key "my_key" # so that it can be >> my_hash[:my_key] => ["Value1","Value2"]
解决方法
我不知道我是否错过了你的观点,但你考虑过以下几点:
1.9.3 (main):0 > h={} => {} 1.9.3 (main):0 > h[:key] = [] => [] 1.9.3 (main):0 > h[:key] << "value1" => ["value1"] 1.9.3 (main):0 > h[:key] << "value2" => ["value1","value2"] 1.9.3 (main):0 > h[:key] => ["value1","value2"]