Skip to content

Commit 9be6e42

Browse files
[DOC] Tweaks for Hash#[]= (ruby#12695)
1 parent 8cafa5b commit 9be6e42

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

hash.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,26 +2900,31 @@ NOINSERT_UPDATE_CALLBACK(hash_aset_str)
29002900

29012901
/*
29022902
* call-seq:
2903-
* hash[key] = value -> value
2904-
* store(key, value)
2903+
* self[key] = object -> object
29052904
*
2906-
* Associates the given +value+ with the given +key+; returns +value+.
2905+
* Associates the given +object+ with the given +key+; returns +object+.
29072906
*
2908-
* If the given +key+ exists, replaces its value with the given +value+;
2907+
* Searches for a hash key equivalent to the given +key+;
2908+
* see {Hash Key Equivalence}[rdoc-ref:Hash@Hash+Key+Equivalence].
2909+
*
2910+
* If the key is found, replaces its value with the given +object+;
29092911
* the ordering is not affected
29102912
* (see {Entry Order}[rdoc-ref:Hash@Entry+Order]):
2913+
*
29112914
* h = {foo: 0, bar: 1}
29122915
* h[:foo] = 2 # => 2
2913-
* h.store(:bar, 3) # => 3
2914-
* h # => {foo: 2, bar: 3}
2916+
* h[:foo] # => 2
29152917
*
2916-
* If +key+ does not exist, adds the +key+ and +value+;
2918+
* If +key+ is not found, creates a new entry for the given +key+ and +object+;
29172919
* the new entry is last in the order
29182920
* (see {Entry Order}[rdoc-ref:Hash@Entry+Order]):
2921+
*
29192922
* h = {foo: 0, bar: 1}
29202923
* h[:baz] = 2 # => 2
2921-
* h.store(:bat, 3) # => 3
2922-
* h # => {foo: 0, bar: 1, baz: 2, bat: 3}
2924+
* h[:baz] # => 2
2925+
* h # => {:foo=>0, :bar=>1, :baz=>2}
2926+
*
2927+
* Related: #[]; see also {Methods for Assigning}[rdoc-ref:Hash@Methods+for+Assigning].
29232928
*/
29242929

29252930
VALUE

0 commit comments

Comments
 (0)