From ba148e71e590d057d930681ae9c93450b9cfef96 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Fri, 14 Feb 2025 15:16:53 -0600 Subject: [PATCH] [DOC] Tweaks for Hash#[] --- hash.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/hash.c b/hash.c index f1b3aca929..b959747206 100644 --- a/hash.c +++ b/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