Ruby convert array to nested hash -
i have following:
value = 42 array = ["this","is","a","test"]
how can convert this
{ "this" => { "is" => { "a" => { "test" => 42 } } } }
the array flat.
thank you!
try this:
h = array.reverse.inject(value) { |a, n| { n => } }
Comments
Post a Comment