mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
1a5a2bae57
commit
b04536fadf
1 changed files with 6 additions and 2 deletions
8
hash.c
8
hash.c
|
@ -1828,12 +1828,16 @@ rb_hash_update(hash1, hash2)
|
||||||
* hsh.merge(other_hash){|key, oldval, newval| block} -> a_hash
|
* hsh.merge(other_hash){|key, oldval, newval| block} -> a_hash
|
||||||
*
|
*
|
||||||
* Returns a new hash containing the contents of <i>other_hash</i> and
|
* 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
|
* the contents of <i>hsh</i>. If no block is specified, the value for
|
||||||
* duplicate keys with those from <i>other_hash</i>.
|
* 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 }
|
* h1 = { "a" => 100, "b" => 200 }
|
||||||
* h2 = { "b" => 254, "c" => 300 }
|
* h2 = { "b" => 254, "c" => 300 }
|
||||||
* h1.merge(h2) #=> {"a"=>100, "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}
|
* h1 #=> {"a"=>100, "b"=>200}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue