Skip to content

Instantly share code, notes, and snippets.

@micahbf
Created April 17, 2015 02:55
Show Gist options
  • Save micahbf/504184be7450d28d3115 to your computer and use it in GitHub Desktop.
Save micahbf/504184be7450d28d3115 to your computer and use it in GitHub Desktop.
Hash#deep_assoc
class Hash
def deep_assoc(*keys)
current = fetch(keys.shift, nil)
return current if keys.empty?
return nil unless current.is_a?(Hash)
current.deep_assoc(*keys)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment