[#45174] [ruby-trunk - Feature #5959][Assigned] Addrinfo#inspectname — Yui NARUSE <naruse@...>
9 messages
2012/02/02
[#45177] Re: [ruby-trunk - Feature #5959][Assigned] Addrinfo#inspectname
— Tanaka Akira <akr@...>
2012/02/02
2012年2月2日17:16 Yui NARUSE <[email protected]>:
[#45178] Re: [ruby-trunk - Feature #5959][Assigned] Addrinfo#inspectname
— Tanaka Akira <akr@...>
2012/02/02
2012年2月2日18:12 Tanaka Akira <[email protected]>:
[#45179] Re: [ruby-trunk - Feature #5959][Assigned] Addrinfo#inspectname
— "NARUSE, Yui" <naruse@...>
2012/02/02
(2012/02/02 18:33), Tanaka Akira wrote:
[#45192] Re: [ruby-trunk - Feature #5959][Assigned] Addrinfo#inspectname
— Tanaka Akira <akr@...>
2012/02/05
2012年2月2日19:13 NARUSE, Yui <[email protected]>:
[#45183] Plan to 1.9.3 1st patch release — "NARUSE, Yui" <naruse@...>
もう気分は 2.0 なので正直 1.9.3 とかどうでもいいんですけど(ぇー)、
8 messages
2012/02/03
[#45184] Re: Plan to 1.9.3 1st patch release
— KOSAKI Motohiro <kosaki.motohiro@...>
2012/02/03
> = backport 時のレビューの廃止
[ruby-dev:45251] [ruby-trunk - Feature #4043] グローバル関数current_classの提案
From:
Shyouhei Urabe <shyouhei@...>
Date:
2012-02-15 09:05:12 UTC
List:
ruby-dev #45251
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/