Skip to content
instance method

Array#dig

(::int idx) -> Elem?
(::int idx, untyped, *untyped) -> untyped
dig(index, *identifiers) → object

Finds and returns the object in nested object specified by index and identifiers; the nested objects may be instances of various classes. See Dig Methods.

Examples:

Example
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

Related: see Methods for Fetching.

See also #difference #drop #detect #drop_while also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0