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

Joshua Partogi joshua.java at gmail.com
Thu Feb 24 05:47:40 EST 2011


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




More information about the riak-users mailing list