Sha256: 5b2487ea7aa5cbfa1f5113f0b607dcbcfe72769679758b09e67f531e75af9b1b
Contents?: true
Size: 725 Bytes
Versions: 26
Compression:
Stored size: 725 Bytes
Contents
module Kernel # Anything that can be marshaled can be copied in totality. # This is also commonly called a deep_copy. # # "ABC".copy #=> "ABC" # def copy Marshal::load(Marshal::dump(self)) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCKernel < Test::Unit::TestCase # fixtures for copy / deep_copy class A attr_reader :a def initialize @a = 1 end end class B attr_reader :b def initialize @b = A.new end end def test_copy o = B.new oc = o.copy assert_equal( 1, o.b.a ) end end =end
Version data entries
26 entries across 26 versions & 1 rubygems