Permalink
Browse files

fix when object cloning

  • Loading branch information...
1 parent bfe49a0 commit 5376ececb2d5d6212952c10a318460131dff94d1 @kachick committed Apr 14, 2012
Showing with 28 additions and 1 deletion.
  1. +6 −1 lib/instancevalue.rb
  2. +22 −0 test/test_instancevalue.rb
View
@@ -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
@@ -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
View
@@ -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.