注意:两个哈希值具有相同的键和相同的值
a = {:ip=>'192.168.2.1',:b=>2}
b = {:ip=>'192.168.2.1',:c=>4}
我想将它们合并到像这样的新哈希
newhash= {:ip=>'192.168.2.1',:b=>2,:c=4}
答案 0 :(得分:2)
a = {:ip=>"192.168.2.1", :b=>2}
b = {:ip=>"192.168.2.1", :c=>4}
newhash = a.merge(b)
#=> {:ip=>"192.168.2.1", :b=>2, :c=>4}