Sha256: d0b523f18da2b6fe983946636276340ccb574c1d94a89141d32e0ed9a7dd21d2

Contents?: true

Size: 406 Bytes

Versions: 6

Compression:

Stored size: 406 Bytes

Contents

# Backport Hash#dig to Ruby < 2.3
# inspired by https://github.com/Invoca/ruby_dig

module HashDig
  def dig(key, *rest)
    value = self[key]
    if value.nil? || rest.empty?
      value
    elsif value.respond_to?(:dig)
      value.dig(*rest)
    else
      raise TypeError, "#{value.class} does not have #dig method"
    end
  end
end

if RUBY_VERSION < '2.3'
  class Hash
    include HashDig
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lolcommits-0.12.1 lib/core_ext/hash/hash_dig.rb
lolcommits-0.12.0 lib/core_ext/hash/hash_dig.rb
lolcommits-0.11.0 lib/core_ext/hash/hash_dig.rb
lolcommits-0.11.0.pre lib/core_ext/hash/hash_dig.rb
lolcommits-0.10.0 lib/core_ext/hash/hash_dig.rb
lolcommits-0.10.0.pre1 lib/core_ext/hash/hash_dig.rb