[DOC] Tweaks for Hash#[]
This commit is contained in:
parent
9be6e4207b
commit
ba148e71e5
Notes:
git
2025-02-14 21:17:10 +00:00
Merged: https://github.com/ruby/ruby/pull/12694 Merged-By: peterzhu2118 <peter@peterzhu.ca>
19
hash.c
19
hash.c
@ -2090,16 +2090,19 @@ rb_hash_stlike_lookup(VALUE hash, st_data_t key, st_data_t *pval)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* hash[key] -> value
|
* self[key] -> object
|
||||||
*
|
*
|
||||||
* Returns the value associated with the given +key+, if found:
|
* Searches for a hash key equivalent to the given +key+;
|
||||||
* h = {foo: 0, bar: 1, baz: 2}
|
* see {Hash Key Equivalence}[rdoc-ref:Hash@Hash+Key+Equivalence].
|
||||||
* h[:foo] # => 0
|
|
||||||
*
|
*
|
||||||
* If +key+ is not found, returns a default value
|
* If the key is found, returns its value:
|
||||||
* (see {Hash Default}[rdoc-ref:Hash@Hash+Default]):
|
*
|
||||||
* h = {foo: 0, bar: 1, baz: 2}
|
* {foo: 0, bar: 1, baz: 2}
|
||||||
* h[:nosuch] # => nil
|
* h[:bar] # => 1
|
||||||
|
*
|
||||||
|
* Otherwise, returns a default value (see {Hash Default}[rdoc-ref:Hash@Hash+Default]).
|
||||||
|
*
|
||||||
|
* Related: #[]=; see also {Methods for Fetching}[rdoc-ref:Hash@Methods+for+Fetching].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user