@@ -1879,11 +1879,11 @@ rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
1879
1879
* hsh.merge!(other_hash){|key, oldval, newval| block} -> hsh
1880
1880
* hsh.update(other_hash){|key, oldval, newval| block} -> hsh
1881
1881
*
1882
- * Adds the contents of <i>other_hash</i> to <i>hsh</i> . If no
1883
- * block is specified, entries with duplicate keys are overwritten
1884
- * with the values from <i>other_hash</i>, otherwise the value
1885
- * of each duplicate key is determined by calling the block with
1886
- * the key, its value in <i>hsh</i> and its value in <i>other_hash</i> .
1882
+ * Adds the contents of _other_hash_ to _hsh_ . If no block is specified,
1883
+ * entries with duplicate keys are overwritten with the values from
1884
+ * _other_hash_, otherwise the value of each duplicate key is determined by
1885
+ * calling the block with the key, its value in _hsh_ and its value in
1886
+ * _other_hash_ .
1887
1887
*
1888
1888
* h1 = { "a" => 100, "b" => 200 }
1889
1889
* h2 = { "b" => 254, "c" => 300 }
@@ -1893,6 +1893,19 @@ rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
1893
1893
* h2 = { "b" => 254, "c" => 300 }
1894
1894
* h1.merge!(h2) { |key, v1, v2| v1 }
1895
1895
* #=> {"a"=>100, "b"=>200, "c"=>300}
1896
+ *
1897
+ * Note that this method creates a shallow copy of the value in _other_hash_.
1898
+ * This means that when for example Array#select! is used on one of the values
1899
+ * in _other_hash_ both the original object as well as the copy will be
1900
+ * modified. This is illustrated in the following example:
1901
+ *
1902
+ * original = { "numbers" => [10, 20, 30] }
1903
+ * copy = {}.merge(original)
1904
+ *
1905
+ * copy["numbers"].select! { |number| number <= 20 }
1906
+ *
1907
+ * puts copy # => { "numbers" => [10, 20] }
1908
+ * puts original # => { "numbers" => [10, 20] }
1896
1909
*/
1897
1910
1898
1911
static VALUE
0 commit comments