Issue #4043 has been updated by Shyouhei Urabe.


Makoto Kishimoto wrote:
> ?????妨?????????????????????????????????????????????

?????????????????????????????????????????対?????????人?????????????????????????????
----------------------------------------
Feature #4043: ???????????current_class?????
https://bugs.ruby-lang.org/issues/4043

Author: Makoto Kishimoto
Status: Open
Priority: Low
Assignee: 
Category: core
Target version: 2.0.0


=begin
 ????????????MRI??????????????????????cref????Ruby??????調?????????????????current_class?????????????????
 ????????????Kernel?????????????????????????????????????self???????????????????????????????????????????????????????????????????????????????
 ??????????????????????以????????????????????????instance_eval???module_eval??????????Ruby????????????確??????????????????????Ruby????解?役?????????
 
 $ irb19
 irb(main):001:0> module M ; end
 => nil
 irb(main):002:0> M.instance_eval { current_class }
 => #<Class:M>
 irb(main):003:0> M.module_eval { current_class }
 => M
 
 差??????????????????????????????????????修正?????????????????????
 
 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 = 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)
=end



-- 
http://bugs.ruby-lang.org/