summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'object.c')
-rw-r--r--object.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/object.c b/object.c
index 410c964d0ea..b9333f75d8e 100644
--- a/object.c
+++ b/object.c
@@ -113,10 +113,14 @@ static VALUE
rb_obj_dup(obj)
VALUE obj;
{
- VALUE dup;
-
if (TYPE(obj) == T_OBJECT) {
- dup = rb_obj_alloc(RBASIC(obj)->klass);
+ VALUE klass = CLASS_OF(obj);
+ VALUE dup;
+
+ while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
+ klass = (VALUE)RCLASS(klass)->super;
+ }
+ dup = rb_obj_alloc(klass);
if (ROBJECT(obj)->iv_tbl) {
ROBJECT(dup)->iv_tbl = st_copy(ROBJECT(obj)->iv_tbl);
}