diff options
author | Burdette Lamar <BurdetteLamar@Yahoo.com> | 2020-08-13 13:16:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-13 13:16:27 -0500 |
commit | 22fd617aa5a8dd9c8426a546e0cb8a64b45c230b (patch) | |
tree | faed339ece1bb59fb3dc0e67184127bb75e67589 /array.c | |
parent | cead77d809e2a7610afc68c395f12007472a72a7 (diff) | |
download | ruby-22fd617aa5a8dd9c8426a546e0cb8a64b45c230b.tar.gz |
Adding doc/dig_methods.rdoc and links to it (#3416)
Adds a full discussion of #dig, along with links from Array, Hash, Struct, and OpenStruct.
CSV::Table and CSV::Row are over in ruby/csv. I'll get to them soon.
The art to the thing is to figure out how much (or how little) to say at each #dig.
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -8639,19 +8639,20 @@ rb_ary_one_p(int argc, VALUE *argv, VALUE ary) } /* - * call-seq: - * ary.dig(idx, ...) -> object - * - * Extracts the nested value specified by the sequence of <i>idx</i> - * objects by calling +dig+ at each step, returning +nil+ if any - * intermediate step is +nil+. + * call-seq: + * array.dig(index, *identifiers) -> object * - * a = [[1, [2, 3]]] + * Finds and returns the object in nested objects + * that is specified by +index+ and +identifiers+. + * The nested objects may be instances of various classes. + * See {Dig Methods}[doc/dig_methods_rdoc.html]. * - * a.dig(0, 1, 1) #=> 3 - * a.dig(1, 2, 3) #=> nil - * a.dig(0, 0, 0) #=> TypeError: Integer does not have #dig method - * [42, {foo: :bar}].dig(1, :foo) #=> :bar + * Examples: + * a = [:foo, [:bar, :baz, [:bat, :bam]]] + * a.dig(1) # => [:bar, :baz, [:bat, :bam]] + * a.dig(1, 2) # => [:bat, :bam] + * a.dig(1, 2, 0) # => :bat + * a.dig(1, 2, 3) # => nil */ static VALUE |