7stud -- wrote in post #994963:
>
...and you can even get rid of that ugly if check every time through the
loop:
str = 'projects.risks.Index.flash_downloading=Downloading.test'
key_str, val = str.split('=')
keys = key_str.split(/[.]/)
temp = master = {}
last = keys.pop
keys.each do |key|
temp = temp[key] = {}
end
temp[last] = val
p master
--output:--
{"projects"=>{"risks"=>{"Index"=>{"flash_downloading"=>"Downloading.test"}}}}
--
Posted via http://www.ruby-forum.com/.