nested = 3.times.inject({}) do |hash, _| Hash.new do |h, k| h[k] = hash end end nested[:foo][:bar][:baz][:quux] = true nested # => {:foo=>{:bar=>{:baz=>{:quux=>true}}}} # “ Be alone, that is the secret of invention; be alone, that is when ideas are born. ” Nikola Tesla