Skip to content

Instantly share code, notes, and snippets.

@longlostnick
Created July 14, 2015 20:36
Show Gist options
  • Save longlostnick/0b828fa4f4fc4f5d68cc to your computer and use it in GitHub Desktop.
Save longlostnick/0b828fa4f4fc4f5d68cc to your computer and use it in GitHub Desktop.
"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