Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_dig.rb

Instance Method Summary collapse

Instance Method Details

#dig(first_key, *other_keys) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/hash_dig.rb', line 3

def dig first_key, *other_keys
  val = self[first_key]
  if other_keys.empty?
    val
  elsif val and val.kind_of? Hash
    val.dig *other_keys
  else
    nil
  end
end