lib/hash_extensions.rb
# Search for key path in hash
#
# Examples
#
#   { a: { b: :c } }.dig(:a, :b) # => :c
#   { a: { 'b' => :c } }.dig(:a, :b) # => :c
#   { a: { b: :c } }.dig(:a, :c) # => nil
Search for key path in hash
Examples


Search for key path in hash Examples
def dig(*path)
    path.reduce(self) do |location, key|
      location.respond_to?(:keys) ? location.stringify_keys[key.to_s] : nil
    end
  end
def dig ( * path ) path . reduce ( self ) do | location , key | location . respond_to? ( :keys ) ? location . stringify_keys [ key . to_s ] : nil end end
Search for key path in hash
Examples
Search for key path in hash Examples
path