hsh = {:one => 1, :two => 2}
=> {:two=>2, :one=>1}
outer = {:hello => :goodbye, :numbers => hsh}
=> {:hello=>:goodbye, :numbers=>{:two=>2, :one=>1}}
outer2 = outer.dup
=> {:hello=>:goodbye, :numbers=>{:two=>2, :one=>1}}
outer2[:numbers][:three] = 3
=> 3
outer2
=> {:hello=>:goodbye, :numbers=>{:three=>3, :two=>2, :one=>1}}
outer
=> {:hello=>:goodbye, :numbers=>{:three=>3, :two=>2, :one=>1}}
And now, for something completely different.
hsh = {:one => 1, :two => 2}
=> {:two=>2, :one=>1}
outer = {:hello => :goodbye, :numbers => hsh}
=> {:hello=>:goodbye, :numbers=>{:two=>2, :one=>1}}
outer2 = Marshal.load(Marshal.dump(outer))
=> {:hello=>:goodbye, :numbers=>{:one=>1, :two=>2}}
outer2
=> {:hello=>:goodbye, :numbers=>{:one=>1, :two=>2}}
outer2[:numbers][:three] = 3
=> 3
outer2
=> {:hello=>:goodbye, :numbers=>{:three=>3, :one=>1, :two=>2}}
outer
=> {:hello=>:goodbye, :numbers=>{:two=>2, :one=>1}}
Deep copying can be pretty important. This seems like the performant way to do it.