更新代码:
irb(main):001:0> h1 = { "a" => 100, "b" => 200 }
=> {"a"=>100, "b"=>200}
irb(main):002:0> h2 = { "b" => 254, "c" => 300 }
=> {"b"=>254, "c"=>300}
irb(main):003:0> h1.update(h2)
=> {"a"=>100, "b"=>254, "c"=>300}
合并代码:
irb(main):001:0> h1 = { "a" => 100, "b" => 200 }
=> {"a"=>100, "b"=>200}
irb(main):002:0> h2 = { "b" => 254, "c" => 300 }
=> {"b"=>254, "c"=>300}
irb(main):003:0> h1.merge(h2)
=> {"a"=>100, "b"=>254, "c"=>300}
irb(main):004:0>
merge
我在相同的情况下运行了上述update
方法hash
。但是得到了相同的输出。所以我的问题是:是否使用相同update
的merge
逻辑?如果不一样,那么输出如何相同?