mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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.
This commit is contained in:
parent
cead77d809
commit
22fd617aa5
Notes:
git
2020-08-14 03:16:50 +09:00
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
5 changed files with 121 additions and 75 deletions
19
struct.c
19
struct.c
|
@ -1328,18 +1328,21 @@ rb_struct_size(VALUE s)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* struct.dig(key, ...) -> object
|
||||
* struct.dig(key, *identifiers) -> object
|
||||
*
|
||||
* Extracts the nested value specified by the sequence of +key+
|
||||
* objects by calling +dig+ at each step, returning +nil+ if any
|
||||
* intermediate step is +nil+.
|
||||
* Finds and returns the object in nested objects
|
||||
* that is specified by +key+ and +identifiers+.
|
||||
* The nested objects may be instances of various classes.
|
||||
* See {Dig Methods}[doc/dig_methods_rdoc.html].
|
||||
*
|
||||
* Examples:
|
||||
* Foo = Struct.new(:a)
|
||||
* f = Foo.new(Foo.new({b: [1, 2, 3]}))
|
||||
*
|
||||
* f.dig(:a, :a, :b, 0) # => 1
|
||||
* f.dig(:b, 0) # => nil
|
||||
* f.dig(:a, :a, :b, :c) # TypeError: no implicit conversion of Symbol into Integer
|
||||
* f.dig(:a) # => #<struct Foo a={:b=>[1, 2, 3]}>
|
||||
* f.dig(:a, :a) # => {:b=>[1, 2, 3]}
|
||||
* f.dig(:a, :a, :b) # => [1, 2, 3]
|
||||
* f.dig(:a, :a, :b, 0) # => 1
|
||||
* f.dig(:b, 0) # => nil
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue