Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"Dig" through hash using dot notation
class Hash
def dig(dotted_path)
parts = dotted_path.split '.', 2
first_part = parts[0]
match = self[first_part] || self[first_part.to_sym]
if !parts[1] || match.nil?
return match
else
return match.dig(parts[1])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.