[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:
|
||||
* hash[key] -> value
|
||||
* self[key] -> object
|
||||
*
|
||||
* Returns the value associated with the given +key+, if found:
|
||||
* h = {foo: 0, bar: 1, baz: 2}
|
||||
* h[:foo] # => 0
|
||||
* Searches for a hash key equivalent to the given +key+;
|
||||
* see {Hash Key Equivalence}[rdoc-ref:Hash@Hash+Key+Equivalence].
|
||||
*
|
||||
* If +key+ is not found, returns a default value
|
||||
* (see {Hash Default}[rdoc-ref:Hash@Hash+Default]):
|
||||
* h = {foo: 0, bar: 1, baz: 2}
|
||||
* h[:nosuch] # => nil
|
||||
* If the key is found, returns its value:
|
||||
*
|
||||
* {foo: 0, bar: 1, baz: 2}
|
||||
* 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user