summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-23 02:35:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-23 02:35:58 +0000
commitc2a04d87d0f51e871e2fc0254ce6f90136b50169 (patch)
tree968463bfcd8001f0940b5ee9654a49437a93b4f9 /vm_eval.c
parent3badcfc1cb87a85ff2d45896be053f12a0958356 (diff)
vm_eval.c: allow symbols to instance_eval/exec
* vm_eval.c (rb_obj_instance_eval, rb_obj_instance_exec): allow symbols to just instance_eval/exec, execept for definition of singletons. [ruby-core:68961] [Bug #11086] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/vm_eval.c b/vm_eval.c
index b63eec2..281dbe7 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1627,6 +1627,20 @@ specific_eval(int argc, const VALUE *argv, VALUE klass, VALUE self)
}
}
+static VALUE
+singleton_class_for_eval(VALUE self)
+{
+ if (SPECIAL_CONST_P(self)) {
+ return rb_special_singleton_class(self);
+ }
+ switch (BUILTIN_TYPE(self)) {
+ case T_FLOAT: case T_BIGNUM: case T_SYMBOL:
+ return Qnil;
+ default:
+ return rb_singleton_class(self);
+ }
+}
+
/*
* call-seq:
* obj.instance_eval(string [, filename [, lineno]] ) -> obj
@@ -1663,14 +1677,7 @@ specific_eval(int argc, const VALUE *argv, VALUE klass, VALUE self)
VALUE
rb_obj_instance_eval(int argc, const VALUE *argv, VALUE self)
{
- VALUE klass;
-
- if (SPECIAL_CONST_P(self)) {
- klass = rb_special_singleton_class(self);
- }
- else {
- klass = rb_singleton_class(self);
- }
+ VALUE klass = singleton_class_for_eval(self);
return specific_eval(argc, argv, klass, self);
}
@@ -1695,14 +1702,7 @@ rb_obj_instance_eval(int argc, const VALUE *argv, VALUE self)
VALUE
rb_obj_instance_exec(int argc, const VALUE *argv, VALUE self)
{
- VALUE klass;
-
- if (SPECIAL_CONST_P(self)) {
- klass = rb_special_singleton_class(self);
- }
- else {
- klass = rb_singleton_class(self);
- }
+ VALUE klass = singleton_class_for_eval(self);
return yield_under(klass, self, rb_ary_new4(argc, argv));
}