summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-05-01 09:42:38 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-05-01 09:42:38 +0000
commitfedf48986da718580062d081dda38c4ee182c254 (patch)
tree65e06d76c544a8d80296d686bf88ec3af41fdc50 /class.c
parentacbb1c943457d3b8802f099ee0e34331bc78bd38 (diff)
2000-05-01
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/class.c b/class.c
index 4048305..413355f 100644
--- a/class.c
+++ b/class.c
@@ -1,4 +1,4 @@
-/************************************************
+/**********************************************************************
class.c -
@@ -8,7 +8,7 @@
Copyright (C) 1993-2000 Yukihiro Matsumoto
-************************************************/
+**********************************************************************/
#include "ruby.h"
#include "node.h"
@@ -502,15 +502,30 @@ rb_undef_method(klass, name)
rb_add_method(klass, rb_intern(name), 0, NOEX_UNDEF);
}
+#define SPECIAL_SINGLETON(x,c) if (obj == (x)) {\
+ if (!FL_TEST(c, FL_SINGLETON)) {\
+ c = rb_singleton_class_new(c);\
+ rb_singleton_class_attached(c,obj);\
+ }\
+ return c;\
+}
+
VALUE
rb_singleton_class(obj)
VALUE obj;
{
VALUE klass;
- if (rb_special_const_p(obj)) {
+ if (FIXNUM_P(obj) || SYMBOL_P(obj)) {
rb_raise(rb_eTypeError, "can't define singleton");
}
+ if (rb_special_const_p(obj)) {
+ SPECIAL_SINGLETON(Qnil, rb_cNilClass);
+ SPECIAL_SINGLETON(Qfalse, rb_cFalseClass);
+ SPECIAL_SINGLETON(Qtrue, rb_cTrueClass);
+ rb_bug("unknown immediate %d", obj);
+ }
+
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON)) {
klass = RBASIC(obj)->klass;
}