Sha256: 97856dd7e051bbc715d6680c9bfc2c666d9d822cecbf2a50fd6c4265bf50bdb3

Contents?: true

Size: 284 Bytes

Versions: 5

Compression:

Stored size: 284 Bytes

Contents

class Hash
  def deep_fetch(key, default = nil)
    keys = key.to_s.split('.')
    dig(*keys) || default rescue default
  end
end

class Array
  def deep_fetch(index, default = nil)
    indexes = index.to_s.split('.').map(&:to_i)
    dig(*indexes) || default rescue default
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
json_logic-0.4.1 lib/core_ext/deep_fetch.rb
json_logic-0.4.0 lib/core_ext/deep_fetch.rb
json_logic-0.3 lib/core_ext/deep_fetch.rb
json_logic-0.1 lib/core_ext/deep_fetch.rb
json_logic-0.0.1 lib/core_ext/deep_fetch.rb