Created
November 21, 2013 07:10
-
-
Save andreaseriksson/7577235 to your computer and use it in GitHub Desktop.
Converts a dotted hash to nested hash
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 to_dotted_hash(hash, recursive_key = "") | |
hash.each_with_object({}) do |(k, v), ret| | |
key = recursive_key + k.to_s | |
if v.is_a? Hash | |
ret.merge! to_dotted_hash(v, key + ".") | |
else | |
ret[key] = v | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment