Object#dupã¯shallow copyã§ãããã©ãMarshal.dumpã¨Marshal.loadã§deep copyã«ãªãã¾ãã a = ["A", ["B", "C"]] # dup - shallow copy b = a.dup p a == b #=> true p a.object_id == b.object_id #=> false p a[0].object_id == b[0].object_id #=> true p a[1].object_id == b[1].object_id #=> true # dump+load - deep copy c = Marshal.load(Marshal.dump(a)) p a == c #=> true p a.object_id == c.object_id #=> false p a[0].object_id
{{#tags}}- {{label}}
{{/tags}}