summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-10 20:18:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-10 20:18:39 +0000
commit5915dc245e5efac34d676ad29ebd38d6b46f16cf (patch)
tree96a07496fbd0e748f38fd6d178fa5ffda1bd373e /class.c
parent399bb7e73953bc7fbeb74e2712d931f44d7553b8 (diff)
* class.c (rb_make_metaclass): [new]
* class.c (rb_define_class_id): use rb_make_metaclass(), don't call Class#inherited hook. * class.c (rb_class_inherited): [new] * class.c (rb_define_class): call Class#inherited hook here. * class.c (rb_define_class_under): ditto after class path is set. * class.c (rb_singleton_class): use rb_make_metaclass(). * eval.c (rb_eval): same as rb_define_class_under(). * intern.h: prototypes of rb_make_metaclass() and rb_class_inherited(). * object.c (rb_class_s_new): use rb_make_metaclass() and rb_class_inherited(). * object.c (Init_Object): use rb_make_metaclass(). * struct.c (make_struct): use rb_class_inherited(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/class.c b/class.c
index 238c3b3..070b413 100644
--- a/class.c
+++ b/class.c
@@ -142,6 +142,16 @@ rb_singleton_class_attached(klass, obj)
}
VALUE
+rb_make_metaclass(obj, klass)
+ VALUE obj, klass;
+{
+ klass = rb_singleton_class_new(klass);
+ RBASIC(obj)->klass = klass;
+ rb_singleton_class_attached(klass, obj);
+ return klass;
+}
+
+VALUE
rb_define_class_id(id, super)
ID id;
VALUE super;
@@ -151,15 +161,19 @@ rb_define_class_id(id, super)
if (!super) super = rb_cObject;
klass = rb_class_new(super);
rb_name_class(klass, id);
- /* make metaclass */
- RBASIC(klass)->klass = rb_singleton_class_new(RBASIC(super)->klass);
- rb_singleton_class_attached(RBASIC(klass)->klass, klass);
- rb_funcall(super, rb_intern("inherited"), 1, klass);
+ rb_make_metaclass(klass, RBASIC(super)->klass);
return klass;
}
VALUE
+rb_class_inherited(super, klass)
+ VALUE super, klass;
+{
+ return rb_funcall(super, rb_intern("inherited"), 1, klass);
+}
+
+VALUE
rb_define_class(name, super)
const char *name;
VALUE super;
@@ -179,6 +193,7 @@ rb_define_class(name, super)
return klass;
}
klass = rb_define_class_id(id, super);
+ rb_class_inherited(super, klass);
st_add_direct(rb_class_tbl, id, klass);
return klass;
@@ -205,8 +220,9 @@ rb_define_class_under(outer, name, super)
return klass;
}
klass = rb_define_class_id(id, super);
- rb_const_set(outer, id, klass);
rb_set_class_path(klass, outer, name);
+ rb_class_inherited(super, klass);
+ rb_const_set(outer, id, klass);
return klass;
}
@@ -653,9 +669,7 @@ rb_singleton_class(obj)
klass = RBASIC(obj)->klass;
}
else {
- klass = rb_singleton_class_new(RBASIC(obj)->klass);
- RBASIC(obj)->klass = klass;
- rb_singleton_class_attached(klass, obj);
+ klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
}
if (OBJ_TAINTED(obj)) {
OBJ_TAINT(klass);