recursion - Ruby dot notation to nested hash keys -


what's best way of converting dot notation path (or array of strings) nested hash key-value? ex: need convert 'foo.bar.baz' equal 'qux' this:

{     'foo' => {         'bar' => {             'baz' => 'qux'         }     } } 

i've done in php, managed creating key in array , setting tmp variable array key's value reference changes take place in array.

try this

f = "root/sub-1/sub-2/file"    f.split("/").reverse.inject{|a,n| {n=>a}} #=>{"root"=>{"sub-1"=>{"sub-2"=>"file"}}} 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -