0.02
No commit activity in last 3 years
No release in over 3 years
Add support for deep cloning to objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
= 3.0.1
 Project Readme

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