aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-13 09:12:04 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-13 09:12:04 +0000
commitaae1d28b6f33d1237e576317497d22158114f103 (patch)
tree23ee19f14aad054a990f6df5ff3178d4d47ed42c
parentd40ef8a85c271c3570e778fb74f53d6401281a9d (diff)
downloadruby-aae1d28b6f33d1237e576317497d22158114f103.tar.gz
proc.c: original_name
* proc.c (method_original_name): new methods Method#original_name and UnboundMethod#original_name. [ruby-core:52048] [Bug #7806] [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39223 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--proc.c18
-rw-r--r--test/ruby/test_method.rb1
3 files changed, 24 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e685098ac..4c11a73c44 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-Wed Feb 13 18:10:09 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Feb 13 18:11:59 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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]
diff --git a/proc.c b/proc.c
index 6951562b27..6424eeb4ff 100644
--- a/proc.c
+++ b/proc.c
@@ -1160,6 +1160,22 @@ method_name(VALUE obj)
/*
* 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)
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)
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);
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 2ef37c4af6..ad68357ddf 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -194,6 +194,7 @@ class TestMethod < Test::Unit::TestCase
end
m = o.method(:bar)
assert_equal(:bar, m.name)
+ assert_equal(:foo, m.original_name)
end
def test_instance_method