Module: Diggable
- Defined in:
- lib/mug/diggable.rb
Overview
Extend any class or object that implements a #[] method, to also have #dig
Instance Method Summary collapse
-
#dig(*idx) ⇒ Object
Extracts the nested value specified by the sequence of
idxobjects by callingdigat each step, returningnilif any intermediate step isnil.
Instance Method Details
#dig(*idx) ⇒ Object
Extracts the nested value specified by the sequence of idx objects by calling dig at each step, returning nil if any intermediate step is nil.
12 13 14 15 16 |
# File 'lib/mug/diggable.rb', line 12 def dig *idx inner = self[idx.shift] return inner if idx.empty? || inner.nil? inner.dig(*idx) end |