Skip to content

Instantly share code, notes, and snippets.

@n-soda
Created February 28, 2017 10:04
Show Gist options
  • Save n-soda/0dcd6092c72d140230bfd1cdd8364bcc to your computer and use it in GitHub Desktop.
Save n-soda/0dcd6092c72d140230bfd1cdd8364bcc to your computer and use it in GitHub Desktop.
def recursive_conv_array_to_hash(h)
h.each{|key, value|
if value.is_a?(Array)
hh = {}
value.each{|e| hh[e]=0 }
h[key] = hh
else
recursive_conv_array_to_hash value
end
}
end
h = {'a'=>{'aa'=>['aaa','aab']}, 'b'=>['bb','bc']}
puts h
recursive_conv_array_to_hash h
puts h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment