Skip to content

Instantly share code, notes, and snippets.

View impurist's full-sized avatar
🎸
Lets play

Steven Holloway impurist

🎸
Lets play
  • Melbourne, Australia
View GitHub Profile
@stuffmc
stuffmc / value_for_key_path.rb
Created September 17, 2011 12:29
Ruby Implementation of "valueForKeyPath"
class Hash
def key_path(dotted_path)
# see http://stackoverflow.com/questions/7139471/transform-a-ruby-hash-into-a-dotted-path-key-string
parts = dotted_path.split '.', 2
match = self[parts[0]]
if !parts[1] or match.nil?
return match
else
return match.key_path(parts[1])
end