[前][次][番号順一覧][スレッド一覧]

ruby-changes:27171

From: nobu <ko1@a...>
Date: Wed, 13 Feb 2013 18:12:14 +0900 (JST)
Subject: [ruby-changes:27171] nobu:r39223 (trunk): proc.c: original_name

nobu	2013-02-13 18:12:04 +0900 (Wed, 13 Feb 2013)

  New Revision: 39223

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39223

  Log:
    proc.c: original_name
    
    * proc.c (method_original_name): new methods Method#original_name and
      UnboundMethod#original_name.  [ruby-core:52048] [Bug #7806]
      [EXPERIMENTAL]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_method.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39222)
+++ ChangeLog	(revision 39223)
@@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Wed Feb 13 18:10:09 2013  Nobuyoshi Nakada  <nobu@r...>
+Wed Feb 13 18:11:59 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (method_original_name): new methods Method#original_name and
+	  UnboundMethod#original_name.  [ruby-core:52048] [Bug #7806]
+	  [EXPERIMENTAL]
 
 	* proc.c (method_inspect): show the given name primarily, and
 	  original_id if aliased.  [ruby-core:52048] [Bug #7806]
Index: proc.c
===================================================================
--- proc.c	(revision 39222)
+++ proc.c	(revision 39223)
@@ -1160,6 +1160,22 @@ method_name(VALUE obj) https://github.com/ruby/ruby/blob/trunk/proc.c#L1160
 
 /*
  *  call-seq:
+ *     meth.original_name    -> symbol
+ *
+ *  Returns the original name of the method.
+ */
+
+static VALUE
+method_original_name(VALUE obj)
+{
+    struct METHOD *data;
+
+    TypedData_Get_Struct(obj, struct METHOD, &method_data_type, data);
+    return ID2SYM(data->me->def->original_id);
+}
+
+/*
+ *  call-seq:
  *     meth.owner    -> class_or_module
  *
  *  Returns the class or module that defines the method.
@@ -2339,6 +2355,7 @@ Init_Proc(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L2355
     rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
     rb_define_method(rb_cMethod, "receiver", method_receiver, 0);
     rb_define_method(rb_cMethod, "name", method_name, 0);
+    rb_define_method(rb_cMethod, "original_name", method_original_name, 0);
     rb_define_method(rb_cMethod, "owner", method_owner, 0);
     rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
     rb_define_method(rb_cMethod, "source_location", rb_method_location, 0);
@@ -2358,6 +2375,7 @@ Init_Proc(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L2375
     rb_define_method(rb_cUnboundMethod, "inspect", method_inspect, 0);
     rb_define_method(rb_cUnboundMethod, "to_s", method_inspect, 0);
     rb_define_method(rb_cUnboundMethod, "name", method_name, 0);
+    rb_define_method(rb_cUnboundMethod, "original_name", method_original_name, 0);
     rb_define_method(rb_cUnboundMethod, "owner", method_owner, 0);
     rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
     rb_define_method(rb_cUnboundMethod, "source_location", rb_method_location, 0);
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 39222)
+++ test/ruby/test_method.rb	(revision 39223)
@@ -194,6 +194,7 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L194
     end
     m = o.method(:bar)
     assert_equal(:bar, m.name)
+    assert_equal(:foo, m.original_name)
   end
 
   def test_instance_method

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]