Skip to content

Instantly share code, notes, and snippets.

@phorsfall
Created December 2, 2009 21:58
Show Gist options
  • Save phorsfall/247643 to your computer and use it in GitHub Desktop.
Save phorsfall/247643 to your computer and use it in GitHub Desktop.
class Hash
def /(key_path)
keys = key_path.split(".")
keys.length > 1 && self[keys[0]] ? self[keys[0]]/keys[1..-1].join(".") : self[key_path]
end
end
# h = { "end" => { "of" => { "the" => { "rainbow" => "gold" }}}}
# h/"end.of.the.rainbow"
# => "gold"
#
# h/"somewhere.over.the.rainbow"
# => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment