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

mod rewrite - Doing external redirect. .htaccess NS flag not working. How to achieve similar results? -

mysql - How to insert just year and month into date field? -