Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
fix when object cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Apr 14, 2012
1 parent bfe49a0 commit 5376ece
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/instancevalue.rb
Expand Up @@ -22,7 +22,7 @@
# person.age #=> age at runtime
# person.instance_eval{val :birthday, Time.now} #=> Exception
module InstanceValue
VERSION = '0.0.2'.freeze
VERSION = '0.0.3'.freeze

module Eigen
private
Expand Down Expand Up @@ -73,6 +73,11 @@ def instance_values

private

def initialize_copy(original)
singleton_class.const_set :VALUES,
original.singleton_class::VALUES.dup
end

def remove_instance_value(name)
if instance_value_defined? name
singleton_class::VALUES.delete name.to_sym
Expand Down
22 changes: 22 additions & 0 deletions test/test_instancevalue.rb
Expand Up @@ -40,4 +40,26 @@ def test_normaly
person.name
end
end

def test_dup
person = Person.new Time.now
person2 = person.dup

assert_equal person.instance_values, person2.instance_values

person2.instance_value_set :newer, 123

assert_same false, (person.instance_values == person2.instance_values)
end

def test_clone
person = Person.new Time.now
person2 = person.clone

assert_equal person.instance_values, person2.instance_values

person2.instance_value_set :newer, 123

assert_same false, (person.instance_values == person2.instance_values)
end
end

0 comments on commit 5376ece

Please sign in to comment.