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

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -