Module: Falcore::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/falcore/util.rb

Instance Method Summary collapse

Instance Method Details

#deep_fetch(hash = {}, *keys) ⇒ Object

Deeply fech the nested keys, returning nil if an item along the pathway returns nil.

Parameters:

  • hash (Hash) (defaults to: {})

    the hash to deep fetch

  • keys (Array)

    the list of keys to fetch (in order)



32
33
34
35
36
37
# File 'lib/falcore/util.rb', line 32

def deep_fetch(hash = {}, *keys)
  keys.inject(hash.dup) do |hash, key|
    return nil if hash.nil?
    hash[key]
  end
end