Skip to content

Instantly share code, notes, and snippets.

@andreaseriksson
Created November 21, 2013 07:10
Show Gist options
  • Save andreaseriksson/7577235 to your computer and use it in GitHub Desktop.
Save andreaseriksson/7577235 to your computer and use it in GitHub Desktop.
Converts a dotted hash to nested hash
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