diff options
| author | BurdetteLamar <burdettelamar@yahoo.com> | 2025-02-17 12:18:56 -0600 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-02-17 19:09:33 -0500 |
| commit | 36f69d5b69711ec3cc27e885a3be2da3e555484c (patch) | |
| tree | fc5c34541378263fe824e91f59614ca518319369 | |
| parent | 266088a85a60f23187b74ad0cea7e125a6b783f6 (diff) | |
[DOC] Tweaks for Hash#dig
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12768
| -rw-r--r-- | hash.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -4619,29 +4619,35 @@ rb_hash_any_p(int argc, VALUE *argv, VALUE hash) * call-seq: * dig(key, *identifiers) -> object * - * Finds and returns the object in nested objects - * that is specified by +key+ and +identifiers+. + * Finds and returns an object found in nested objects, + * as specified by +key+ and +identifiers+. + * * The nested objects may be instances of various classes. * See {Dig Methods}[rdoc-ref:dig_methods.rdoc]. * - * Nested Hashes: + * Nested hashes: + * * h = {foo: {bar: {baz: 2}}} * h.dig(:foo) # => {bar: {baz: 2}} * h.dig(:foo, :bar) # => {baz: 2} * h.dig(:foo, :bar, :baz) # => 2 * h.dig(:foo, :bar, :BAZ) # => nil * - * Nested Hashes and Arrays: + * Nested hashes and arrays: + * * h = {foo: {bar: [:a, :b, :c]}} * h.dig(:foo, :bar, 2) # => :c * - * This method will use the {hash default}[rdoc-ref:Hash@Hash+Default] - * for keys that are not present: + * If no such object is found, + * returns the {hash default}[rdoc-ref:Hash@Hash+Default]: + * * h = {foo: {bar: [:a, :b, :c]}} * h.dig(:hello) # => nil * h.default_proc = -> (hash, _key) { hash } - * h.dig(:hello, :world) # => h - * h.dig(:hello, :world, :foo, :bar, 2) # => :c + * h.dig(:hello, :world) + * # => {:foo=>{:bar=>[:a, :b, :c]}} + * + * Related: {Methods for Fetching}[rdoc-ref:Hash@Methods+for+Fetching]. */ static VALUE |
