Skip to content

Documentation for Hash#merge and shallow copies. #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,20 @@ rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
* h2 = { "b" => 254, "c" => 300 }
* h1.merge!(h2) { |key, v1, v2| v1 }
* #=> {"a"=>100, "b"=>200, "c"=>300}
*
* Note that this method creates a shallow copy of the value in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the values, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, must have missed this one, do you want to commit this one Mr. Daloze?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll take care of it.

* <i>other_hash</i>. This means that when for example
* <code>Array#select!</code> is used on one of the values in
* <i>other_hash</i> both the original object as well as the copy will
* be modified. This is illustrated in the following example:
*
* original = { 'numbers' => [10, 20, 30] }
* copy = {}.merge(original)
*
* copy['numbers'].select! { |number| number <= 20 }
*
* puts copy # => { 'numbers' => [10, 20] }
* puts original # => { 'numbers' => [10, 20] }
*/

static VALUE
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy