ruby-changes:14962
From: marcandre <ko1@a...>
Date: Sun, 7 Mar 2010 02:23:31 +0900 (JST)
Subject: [ruby-changes:14962] Ruby:r26833 (ruby_1_8): * hash.c (Hash#merge doc): Added explanation for form with block.
marcandre 2010-03-07 02:18:53 +0900 (Sun, 07 Mar 2010) New Revision: 26833 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26833 Log: * hash.c (Hash#merge doc): Added explanation for form with block. Modified files: branches/ruby_1_8/hash.c Index: ruby_1_8/hash.c =================================================================== --- ruby_1_8/hash.c (revision 26832) +++ ruby_1_8/hash.c (revision 26833) @@ -1828,12 +1828,16 @@ * hsh.merge(other_hash){|key, oldval, newval| block} -> a_hash * * Returns a new hash containing the contents of <i>other_hash</i> and - * the contents of <i>hsh</i>, overwriting entries in <i>hsh</i> with - * duplicate keys with those from <i>other_hash</i>. + * the contents of <i>hsh</i>. If no block is specified, the value for + * entries with duplicate keys will be that of <i>other_hash</i>. Otherwise + * the value for each duplicate key is determined by calling the block + * with the key, its value in <i>hsh</i> and its value in <i>other_hash</i>. * * 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} * */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/