Suppose we have a nested hash here.
a = {:"0" => {:CA => {:count => 10}}}
if we want to add a new hash pair to that hash, say
a = {:"0" => {:NY => {:count => 11}}}
and let it become
a = {:"0" => {:CA => {:count =>10}, :NY => {:count => 11}}}
what should I do?
I’ve tried
a[:0][:NY][:count] = 11
but get the error “undefined method `[]=’ for nil:NilClass (NoMethodError)”
My guess is that you want to do something like this.
You could also take advantage of merge