Last active
April 14, 2017 01:53
-
-
Save masaomoc/1a58108424399f314142123a63807f8f to your computer and use it in GitHub Desktop.
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 make_parent_path(variables, prefix='') | |
h = {} | |
variables.each do |k,v| | |
key = "#{prefix}#{k.to_s}" | |
if v.is_a? Hash | |
h.merge!(make_parent_path(v, "#{key}.")) | |
else | |
h[key] = v | |
end | |
end | |
h | |
end | |
h = { | |
a: 1, | |
b: { | |
c: 2, | |
d: 3 | |
} | |
} | |
make_parent_hash(h) | |
# { | |
# "a" => 1, | |
# "b.c" => 2, | |
# "b.d" => 3 | |
#} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment