From ad6f06aed8bf9b753622809441c4db0d523cd41f Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 29 Dec 2012 02:37:47 +0000 Subject: object.c: singleton class clone * object.c (rb_obj_clone): attach clone to its singleton class during cloning singleton class so that singleton_method_added will be called on it. based on the patch by shiba (satoshi shiba)[Bug #5283] in [ruby-dev:44477]. [Bug #5283] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- class.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'class.c') diff --git a/class.c b/class.c index 1fc7172d27..36e7b76caf 100644 --- a/class.c +++ b/class.c @@ -239,6 +239,12 @@ rb_mod_init_copy(VALUE clone, VALUE orig) VALUE rb_singleton_class_clone(VALUE obj) +{ + return rb_singleton_class_clone_and_attach(obj, Qundef); +} + +VALUE +rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach) { VALUE klass = RBASIC(obj)->klass; @@ -264,6 +270,9 @@ rb_singleton_class_clone(VALUE obj) RCLASS_CONST_TBL(clone) = st_init_numtable(); st_foreach(RCLASS_CONST_TBL(klass), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone)); } + if (attach != Qundef) { + rb_singleton_class_attached(clone, attach); + } RCLASS_M_TBL(clone) = st_init_numtable(); st_foreach(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)clone); rb_singleton_class_attached(RBASIC(clone)->klass, clone); -- cgit v1.2.3