summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-06 15:31:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-06 15:31:13 +0000
commit28827e61d153e39ad3fe1e6fecbf27c09140fe75 (patch)
tree898387ecb8856fbaa33e2345b1fa4292f7522d61 /class.c
parent353833c466f30accbc96c5121d2b9487db411e2a (diff)
method in instance_eval
* class.c (rb_special_singleton_class_of): utility function. * vm_eval.c (eval_under): special deal for class variable scope with instance_eval. * vm_eval.c (rb_obj_instance_eval, rb_obj_instance_exec): allow method definition in instance_eval of special constants. [ruby-core:28324] [Bug #2788] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/class.c b/class.c
index 4acdc0807d..2ee5b8867a 100644
--- a/class.c
+++ b/class.c
@@ -1286,6 +1286,20 @@ rb_undef_method(VALUE klass, const char *name)
}\
} while (0)
+static inline VALUE
+special_singleton_class_of(VALUE obj)
+{
+ SPECIAL_SINGLETON(Qnil, rb_cNilClass);
+ SPECIAL_SINGLETON(Qfalse, rb_cFalseClass);
+ SPECIAL_SINGLETON(Qtrue, rb_cTrueClass);
+ return Qnil;
+}
+
+VALUE
+rb_special_singleton_class(VALUE obj)
+{
+ return special_singleton_class_of(obj);
+}
/*!
* \internal
@@ -1304,11 +1318,11 @@ singleton_class_of(VALUE 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 %p", (void *)obj);
+ if (SPECIAL_CONST_P(obj)) {
+ klass = special_singleton_class_of(obj);
+ if (NIL_P(klass))
+ rb_bug("unknown immediate %p", (void *)obj);
+ return klass;
}
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&