a = { "x" => 0, "y" => { "z" => 0 } }
#=> {"x"=>0, "y"=>{"z"=>0}
# normal copy, copies reference of a.
b = a
b["y"]["z"] = 1
b
# {"x"=>0, "y"=>{"z"=>1}}
a
# {"x"=>0, "y"=>{"z"=>1}}
# shallow copy, just changes the parent object reference not the child once
c = b.clone
c["x"] = 1
c
# => {"x"=>1, "y"=>{"z"=>2}}
b
# => {"x"=>0, "y"=>{"z"=>2}}
c["y"]["z"] = 3
c
# => {"x"=>1, "y"=>{"z"=>3}}
b
# => {"x"=>0, "y"=>{"z"=>3}}
#deep copy, changes all the child object reference
d = JSON.parse(c.to_json)
#=> {"x"=>1, "y"=>{"z"=>3}}
d["y"]["z"] = 5
c
# => {"x"=>1, "y"=>{"z"=>3}}
d
# => {"x"=>1, "y"=>{"z"=>5}}