Created
December 26, 2020 17:07
-
-
Save timm-oh/040709bb3c791a6ebbbe7e38ecdc42fa to your computer and use it in GitHub Desktop.
Helper method to convert from dot notation to hash
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
def dot_to_hash(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] = dot_to_hash(v) | |
else | |
result[root] = dot_to_hash(v) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment