summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-18 08:47:06 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-18 08:47:06 +0000
commit35f851bcfe7e42ddf1b44606d2df4d4be9de9976 (patch)
tree22b6a55b921d76a6d432f0a2156496ccb827be73 /class.c
parentcd956b3114c1b59de6660e1c70be192c6ee29235 (diff)
* string.c (rb_str_replace): swap arguments of OBJ_INFECT.
* eval.c (rb_thread_schedule): should not select a thread which is not yet initialized. * time.c (time_plus): wrong boundary check. * time.c (time_minus): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/class.c b/class.c
index 48577a7..edfc9dd 100644
--- a/class.c
+++ b/class.c
@@ -170,7 +170,13 @@ rb_define_class(name, super)
id = rb_intern(name);
if (rb_const_defined(rb_cObject, id)) {
klass = rb_const_get(rb_cObject, id);
- rb_name_error(id, "%s is already defined", name);
+ if (TYPE(klass) != T_CLASS) {
+ rb_raise(rb_eTypeError, "%s is not a class", name);
+ }
+ if (rb_class_real(RCLASS(klass)->super) != super) {
+ rb_name_error(id, "%s is already defined", name);
+ }
+ return klass;
}
klass = rb_define_class_id(id, super);
st_add_direct(rb_class_tbl, id, klass);
@@ -190,7 +196,13 @@ rb_define_class_under(outer, name, super)
id = rb_intern(name);
if (rb_const_defined_at(outer, id)) {
klass = rb_const_get(outer, id);
- rb_name_error(id, "%s is already defined", name);
+ if (TYPE(klass) != T_CLASS) {
+ rb_raise(rb_eTypeError, "%s is not a class", name);
+ }
+ if (rb_class_real(RCLASS(klass)->super) != super) {
+ rb_name_error(id, "%s is already defined", name);
+ }
+ return klass;
}
klass = rb_define_class_id(id, super);
rb_const_set(outer, id, klass);