@@ -4117,53 +4117,48 @@ rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func)
4117
4117
4118
4118
/*
4119
4119
* call-seq:
4120
- * merge -> copy_of_self
4121
4120
* merge(*other_hashes) -> new_hash
4122
4121
* merge(*other_hashes) { |key, old_value, new_value| ... } -> new_hash
4123
4122
*
4124
- * Returns the new +Hash+ formed by merging each of +other_hashes+
4125
- * into a copy of +self+.
4123
+ * Each argument +other_hash+ in +other_hashes+ must be a hash.
4126
4124
*
4127
- * Each argument in +other_hashes+ must be a +Hash+.
4125
+ * With arguments +other_hashes+ given and no block,
4126
+ * returns the new hash formed by merging each successive +other_hash+
4127
+ * into a copy of +self+;
4128
+ * returns that copy;
4129
+ * for each successive entry in +other_hash+:
4128
4130
*
4129
- * ---
4130
- *
4131
- * With arguments and no block:
4132
- * * Returns the new +Hash+ object formed by merging each successive
4133
- * +Hash+ in +other_hashes+ into +self+.
4134
- * * Each new-key entry is added at the end.
4135
- * * Each duplicate-key entry's value overwrites the previous value.
4131
+ * - For a new key, the entry is added at the end of +self+.
4132
+ * - For duplicate key, the entry overwrites the entry in +self+,
4133
+ * whose position is unchanged.
4136
4134
*
4137
4135
* Example:
4136
+ *
4138
4137
* h = {foo: 0, bar: 1, baz: 2}
4139
4138
* h1 = {bat: 3, bar: 4}
4140
4139
* h2 = {bam: 5, bat:6}
4141
4140
* h.merge(h1, h2) # => {foo: 0, bar: 4, baz: 2, bat: 6, bam: 5}
4142
4141
*
4143
- * With arguments and a block:
4144
- * * Returns a new +Hash+ object that is the merge of +self+ and each given hash.
4145
- * * The given hashes are merged left to right.
4146
- * * Each new-key entry is added at the end.
4147
- * * For each duplicate key:
4148
- * * Calls the block with the key and the old and new values.
4149
- * * The block's return value becomes the new value for the entry.
4142
+ * With arguments +other_hashes+ and a block given, behaves as above
4143
+ * except that for a duplicate key
4144
+ * the overwriting entry takes it value not from the entry in +other_hash+,
4145
+ * but instead from the block:
4146
+ *
4147
+ * - The block is called with the duplicate key and the values
4148
+ * from both +self+ and +other_hash+.
4149
+ * - The block's return value becomes the new value for the entry in +self+.
4150
4150
*
4151
4151
* Example:
4152
+ *
4152
4153
* h = {foo: 0, bar: 1, baz: 2}
4153
4154
* h1 = {bat: 3, bar: 4}
4154
4155
* h2 = {bam: 5, bat:6}
4155
- * h3 = h.merge(h1, h2) { |key, old_value, new_value| old_value + new_value }
4156
- * h3 # => {foo: 0, bar: 5, baz: 2, bat: 9, bam: 5}
4156
+ * h.merge(h1, h2) { |key, old_value, new_value| old_value + new_value }
4157
+ * # => {foo: 0, bar: 5, baz: 2, bat: 9, bam: 5}
4157
4158
*
4158
- * With no arguments:
4159
- * * Returns a copy of +self+.
4160
- * * The block, if given, is ignored.
4159
+ * With no arguments, returns a copy of +self+; the block, if given, is ignored.
4161
4160
*
4162
- * Example:
4163
- * h = {foo: 0, bar: 1, baz: 2}
4164
- * h.merge # => {foo: 0, bar: 1, baz: 2}
4165
- * h1 = h.merge { |key, old_value, new_value| raise 'Cannot happen' }
4166
- * h1 # => {foo: 0, bar: 1, baz: 2}
4161
+ * Related: see {Methods for Assigning}[rdoc-ref:Hash@Methods+for+Assigning].
4167
4162
*/
4168
4163
4169
4164
static VALUE
0 commit comments