I have a hash in the database in JSON format. eg
{
\"one\" => {
\"two\" => {
\"three\" => {}
}
}
}
I need to ge
To generate nested hash:
hash = {}
"one.two.three".split('.').reduce(hash) { |h,m| h[m] = {} }
puts hash #=> {"one"=>{"two"=>{"three"=>{}}}}
If you don't have rails installed then install activesupport gem:
gem install activesupport
Then include it into your file:
require 'active_support/core_ext/hash/deep_merge'
hash = {
"one" => {
"two" => {
"three" => {}
}
}
}.deep_merge(another_hash)
The access to the internals would be:
hash['one']['two']['three'] #=> {}