From b04536fadf378c24f871f743b96e40f22ca74adc Mon Sep 17 00:00:00 2001 From: marcandre Date: Sat, 6 Mar 2010 17:18:53 +0000 Subject: [PATCH] * hash.c (Hash#merge doc): Added explanation for form with block. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hash.c b/hash.c index 169abbd52a..f9f8077765 100644 --- a/hash.c +++ b/hash.c @@ -1828,12 +1828,16 @@ rb_hash_update(hash1, hash2) * hsh.merge(other_hash){|key, oldval, newval| block} -> a_hash * * Returns a new hash containing the contents of other_hash and - * the contents of hsh, overwriting entries in hsh with - * duplicate keys with those from other_hash. + * the contents of hsh. If no block is specified, the value for + * entries with duplicate keys will be that of other_hash. Otherwise + * the value for each duplicate key is determined by calling the block + * with the key, its value in hsh and its value in other_hash. * * h1 = { "a" => 100, "b" => 200 } * h2 = { "b" => 254, "c" => 300 } * h1.merge(h2) #=> {"a"=>100, "b"=>254, "c"=>300} + * h1.merge(h2){|key, oldval, newval| newval - oldval} + * #=> {"a"=>100, "b"=>54, "c"=>300} * h1 #=> {"a"=>100, "b"=>200} * */