Project

General

Profile

Feature #12092 » 0001-Allow-clone-to-yield-cloned-object-before-freezing.patch

jeremyevans0 (Jeremy Evans), 02/19/2016 08:33 PM

View differences:

object.c
* s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
* s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
*
* If a block is given, it is yielded the cloned object before the
* cloned object is frozen (if the receiver is frozen).
*
* This method may have class-specific behavior. If so, that
* behavior will be documented under the #+initialize_copy+ method of
* the class.
......
init_copy(clone, obj);
rb_funcall(clone, id_init_clone, 1, obj);
if (rb_block_given_p()) {
rb_yield(clone);
}
RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
return clone;
test/ruby/test_object.rb
assert_throw(:initialize_dup) {obj.dup}
end
def test_clone_with_block
cls = Class.new do
attr_accessor :b
end
obj = cls.new
obj.b = 1
obj.freeze
c = obj.clone{|clone| clone.b = 2}
assert_equal 2, c.b
assert c.frozen?
end
def test_instance_of
assert_raise(TypeError) { 1.instance_of?(1) }
end
(1-1/2)