Created
July 8, 2019 16:13
-
-
Save choncou/57348f90e7559737ee030448a7aac5ff to your computer and use it in GitHub Desktop.
Hash from dot-notation keys
This file contains 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
def hash_from_dot_notation(value) | |
return value unless value.is_a?(Hash) | |
value.deep_stringify_keys.each_with_object({}) do |(k,v), result| | |
root, child = k.split('.') | |
if child | |
result[root] ||= {} | |
result[root][child] = hash_from_dot_notation(v) | |
else | |
result[root] = hash_from_dot_notation(v) | |
end | |
end | |
end |
Author
choncou
commented
Jul 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment