Feature #4043: =E3=82=B0=E3=83=AD=E3=83=BC=E3=83=90=E3=83=AB=E9=96=A2=E6=95=
=B0current_class=E3=81=AE=E6=8F=90=E6=A1=88
http://redmine.ruby-lang.org/issues/show/4043

=E8=B5=B7=E7=A5=A8=E8=80=85: Makoto Kishimoto
=E3=82=B9=E3=83=86=E3=83=BC=E3=82=BF=E3=82=B9: Open, =E5=84=AA=E5=85=88=E5=
=BA=A6: Low
=E3=82=AB=E3=83=86=E3=82=B4=E3=83=AA: core, Target version: 1.9.x

=E3=82=AB=E3=83=AC=E3=83=B3=E3=83=88=E3=82=AF=E3=83=A9=E3=82=B9=EF=BC=88M=
RI=E3=81=AE=E5=86=85=E9=83=A8=E3=81=A7=E3=81=84=E3=81=86=E3=81=A8=E3=81=93=
=E3=82=8D=E3=81=AEcref=EF=BC=89=E3=82=92Ruby=E3=81=8B=E3=82=89=E8=AA=BF=E3=
=81=B9=E3=82=89=E3=82=8C=E3=82=8B=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89curr=
ent_class=E3=82=92=E6=8F=90=E6=A1=88=E3=81=97=E3=81=BE=E3=81=99=E3=80=82
=E3=82=B0=E3=83=AD=E3=83=BC=E3=83=90=E3=83=AB=E9=96=A2=E6=95=B0=EF=BC=88K=
ernel=E3=81=AE=E3=83=97=E3=83=A9=E3=82=A4=E3=83=99=E3=83=BC=E3=83=88=E3=83=
=A1=E3=82=BD=E3=83=83=E3=83=89=EF=BC=89=E3=81=AB=E3=81=99=E3=82=8B=E7=90=86=
=E7=94=B1=E3=81=AF=E3=80=81self=EF=BC=88=E3=81=AA=E3=81=84=E3=81=97=E3=81=
=AA=E3=82=93=E3=82=89=E3=81=8B=E3=81=AE=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7=
=E3=82=AF=E3=83=88=EF=BC=89=E3=81=A8=E3=81=AF=E9=96=A2=E4=BF=82=E3=81=AA=E3=
=81=84=E5=80=A4=E3=82=92=E8=BF=94=E3=81=99=E3=83=A1=E3=82=BD=E3=83=83=E3=83=
=89=E3=81=A7=E3=81=82=E3=82=8B=E3=81=9F=E3=82=81=E3=80=81=E3=81=A7=E3=81=99=
=E3=80=82
=E3=83=A6=E3=83=BC=E3=82=B9=E3=82=B1=E3=83=BC=E3=82=B9=E3=81=A7=E3=81=99=E3=
=81=8C=E3=80=81=E4=BE=8B=E3=81=88=E3=81=B0=E4=BB=A5=E4=B8=8B=E3=81=AE=E3=82=
=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=A6=E3=80=81=E3=83=A2=E3=82=B8=E3=83=A5=
=E3=83=BC=E3=83=AB=E3=81=AEinstance_eval=E3=81=A8module_eval=E3=81=AE=E9=81=
=95=E3=81=84=E3=82=92Ruby=E3=83=97=E3=83=AD=E3=82=B0=E3=83=A9=E3=83=9E=E3=
=81=8C=E7=A2=BA=E3=81=8B=E3=82=81=E3=82=8B=E3=81=93=E3=81=A8=E3=81=8C=E3=81=
=A7=E3=81=8D=E3=80=81Ruby=E3=81=AE=E7=90=86=E8=A7=A3=E3=81=AB=E5=BD=B9=E7=
=AB=8B=E3=81=A1=E3=81=BE=E3=81=99=E3=80=82

$ irb19
irb(main):001:0> module M ; end
=3D> nil
irb(main):002:0> M.instance_eval { current_class }
=3D> #<Class:M>
irb(main):003:0> M.module_eval { current_class }
=3D> M

=E5=B7=AE=E5=88=86=E3=82=92=E4=BB=98=E3=81=91=E3=81=BE=E3=81=99=E3=81=8C=E3=
=80=81=E3=82=AF=E3=82=A4=E3=83=83=E3=82=AF=E3=83=8F=E3=83=83=E3=82=AF=E3=81=
=A7=E3=81=99=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3=E3=81=8C=E5=BF=85=E8=A6=81=
=E3=81=8B=E3=81=A8=E6=80=9D=E3=81=84=E3=81=BE=E3=81=99=E3=80=82

diff --git a/object.c b/object.c
index 75192c1..82ad85a 100644
--- a/object.c
+++ b/object.c
@@ -2408,6 +2408,13 @@ rb_f_array(VALUE obj, VALUE arg)
     return rb_Array(arg);
 }

+VALUE rb_vm_cref_cls(void);
+static VALUE
+rb_f_current_class(VALUE obj)
+{
+    return rb_vm_cref_cls();
+}
+
 /*
  *  Document-class: Class
  *
@@ -2588,6 +2595,8 @@ Init_Object(void)
     rb_define_global_function("String", rb_f_string, 1);
     rb_define_global_function("Array", rb_f_array, 1);

+    rb_define_global_function("current_class", rb_f_current_class, 0);
+
     rb_cNilClass =3D rb_define_class("NilClass", rb_cObject);
     rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0);
     rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
diff --git a/vm.c b/vm.c
index 980e7ea..dcc43df 100644
--- a/vm.c
+++ b/vm.c
@@ -819,6 +819,12 @@ rb_vm_cref(void)
     return vm_get_cref(cfp->iseq, cfp->lfp, cfp->dfp);
 }

+VALUE
+rb_vm_cref_cls(void)
+{
+    return rb_vm_cref()->nd_clss;
+}
+
 #if 0
 void
 debug_cref(NODE *cref)


----------------------------------------
http://redmine.ruby-lang.org
ZGlmZiAtLWdpdCBhL29iamVjdC5jIGIvb2JqZWN0LmMKaW5kZXggNzUxOTJj
MS4uODJhZDg1YSAxMDA2NDQKLS0tIGEvb2JqZWN0LmMKKysrIGIvb2JqZWN0
LmMKQEAgLTI0MDgsNiArMjQwOCwxMyBAQCByYl9mX2FycmF5KFZBTFVFIG9i
aiwgVkFMVUUgYXJnKQogICAgIHJldHVybiByYl9BcnJheShhcmcpOwogfQog
CitWQUxVRSByYl92bV9jcmVmX2Nscyh2b2lkKTsKK3N0YXRpYyBWQUxVRQor
cmJfZl9jdXJyZW50X2NsYXNzKFZBTFVFIG9iaikKK3sKKyAgICByZXR1cm4g
cmJfdm1fY3JlZl9jbHMoKTsKK30KKwogLyoKICAqICBEb2N1bWVudC1jbGFz
czogQ2xhc3MKICAqCkBAIC0yNTg4LDYgKzI1OTUsOCBAQCBJbml0X09iamVj
dCh2b2lkKQogICAgIHJiX2RlZmluZV9nbG9iYWxfZnVuY3Rpb24oIlN0cmlu
Zy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