Deep cloning magic for Ruby objects.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.rbenv-gemsets
.rbenv-version
Gemfile
LICENSE
README.rdoc
Rakefile
VERSION
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