Sha256: 4d2f1ea950909c873c2158c2c3db1b956f7d308929a203faeb527b6f3225838b

Contents?: true

Size: 735 Bytes

Versions: 26

Compression:

Stored size: 735 Bytes

Contents

module Kernel

  # Anything that can be marshaled can be copied in totality.
  # This is also just called copy.
  #
  #   "ABC".deep_copy  #=> "ABC"
  #
  def deep_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_deep_copy
      o = B.new
      oc = o.deep_copy
      assert_equal( 1, o.b.a  )
    end
  end

=end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
facets-1.8.49 lib/facets/core/kernel/deep_copy.rb
facets-1.8.0 lib/facets/core/kernel/deep_copy.rb
facets-1.8.20 lib/facets/core/kernel/deep_copy.rb
facets-1.8.51 lib/facets/core/kernel/deep_copy.rb
facets-1.8.54 lib/facets/core/kernel/deep_copy.rb
facets-1.8.8 lib/facets/core/kernel/deep_copy.rb