Skip to content

Instantly share code, notes, and snippets.

@timm-oh
Created December 26, 2020 17:07
Show Gist options
  • Save timm-oh/040709bb3c791a6ebbbe7e38ecdc42fa to your computer and use it in GitHub Desktop.
Save timm-oh/040709bb3c791a6ebbbe7e38ecdc42fa to your computer and use it in GitHub Desktop.
Helper method to convert from dot notation to hash
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