Sha256: 47ab8ce2d86d5729d8695db2c44dded123c9fb88053e22eda12034e7863e1577

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

= DeepClonable

DeepClonable is an extension that adds deep clone support to any Class. Just call
deep_clonable in the class definition. You can also define special behavior when cloning
by overriding the clone_fields method if you want, but by default, all Arrays and Hashes
will be deep cloned.

== Usage:

  class Foo
    deep_clonable
    
    attr_reader :array
    
    def initialize(array)
      @array = array
    end
    
    def clone_fields
      # Only deep clone a single variable, all other variables will be just be copied directly.
      @array = @array.clone
    end
  end

  foo = Foo.new([1,2,3])
  bar = Foo.clone

  foo.array
  # => [1,2,3]

  bar.array
  # => [1,2,3]

  bar.array << 4
  bar.array
  # => [1,2,3,4]

  foo.array
  # => [1,2,3]

== Install:

  sudo gem install ninjudd-deep_clonable -s http://gems.github.com

== License:

Copyright (c) 2008 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
deep_clonable-1.2.0 README.rdoc
deep_clonable-1.1.0 README.rdoc
deep_clonable-1.0.2 README.rdoc