Why does ripple cloned object can change the state of original object?

Sean Cribbs sean at basho.com
Thu Feb 24 10:19:53 EST 2011


Ripple::Document does not support cloning at the moment.  Note that Object#clone simply copies the instance variables but doesn't clone them (unless the class overrides #initialize_copy to change that behavior).

Sean Cribbs <sean at basho.com>
Developer Advocate
Basho Technologies, Inc.
http://basho.com/

On Feb 24, 2011, at 5:47 AM, Joshua Partogi wrote:

> Hi,
> 
> I cloned a ripple object and change the state of it. Unfortunately it
> also change to state of the original object. How is this possible? Am
> I doing something wrong? Here is the spec to show the example:
> 
> class Person
>  include Ripple::Document
> 
>  property :name, String
> end
> 
> class Dude
>  attr_accessor :name
> end
> 
> describe 'test' do
>  it "should copy object" do
>    joe = Person.new
>    joe.name = 'Joe'
> 
>    john = joe.clone
>    john.name = 'John'
> 
>    joe.name.should == 'Joe'
>    john.name.should == 'John'
> 
>    joe = Dude.new
>    joe.name = 'Joe'
> 
>    john = joe.clone
>    john.name = 'John'
> 
>    joe.name.should == 'Joe'
>    john.name.should == 'John'
> 
>  end
> end
> 
> The spec will fail when asserting Joe's (Person) name. Please advise
> on how I can resolve this problem.
> 
> Thank you for your assistance.
> 
> Kind regards,
> Joshua.
> 
> -- 
> http://twitter.com/jpartogi
> 
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com





More information about the riak-users mailing list