Created
April 17, 2015 02:55
-
-
Save micahbf/504184be7450d28d3115 to your computer and use it in GitHub Desktop.
Hash#deep_assoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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