Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Deep cloning magic for Ruby objects.
Ruby
tag: v1.0.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
LICENSE
README.rdoc
Rakefile
VERSION.yml
deep_clonable.gemspec

README.rdoc

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 © 2008 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE

Something went wrong with that request. Please try again.