module Ahnnotate::Refinement::Dig

Public Instance Methods

dig(head, *tail) click to toggle source
# File lib/ahnnotate/refinement/dig.rb, line 6
def dig(head, *tail)
  value = self[head]

  if tail.empty? || value.nil?
    return value
  end

  if value.respond_to?(:dig) || value.is_a?(Hash) || value.is_a?(Array)
    value.dig(*tail)
  else
    raise TypeError, "#{value.class} does not have #dig method"
  end
end