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

ruby-changes:64314

From: Rados=C5=82aw <ko1@a...>
Date: Sat, 19 Dec 2020 12:25:00 +0900 (JST)
Subject: [ruby-changes:64314] 51bcd50915 (master): Feature 17314: alias_method returns symbol

https://git.ruby-lang.org/ruby.git/commit/?id=51bcd50915

From 51bcd50915941d21df806e8dcde769ae63b6eaaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Bu=C5=82at?= <radek.bulat@g...>
Date: Fri, 18 Dec 2020 19:14:23 +0100
Subject: Feature 17314: alias_method returns symbol


diff --git a/NEWS.md b/NEWS.md
index 39ddf37..1101f51 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -253,6 +253,9 @@ Outstanding ones only. https://github.com/ruby/ruby/blob/trunk/NEWS.md#L253
       methods now return array of defined methods names as symbols.
       [[Feature #17314]]
 
+    * Module#alias_method now returns the defined alias as symbol.
+      [[Feature #17314]]
+
 * Mutex
 
     * `Mutex` is now acquired per-`Fiber` instead of per-`Thread`. This change
diff --git a/spec/ruby/core/module/alias_method_spec.rb b/spec/ruby/core/module/alias_method_spec.rb
index 742e289..5d3d0c2 100644
--- a/spec/ruby/core/module/alias_method_spec.rb
+++ b/spec/ruby/core/module/alias_method_spec.rb
@@ -85,8 +85,19 @@ describe "Module#alias_method" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/alias_method_spec.rb#L85
     Module.should have_public_instance_method(:alias_method, false)
   end
 
-  it "returns self" do
-    @class.send(:alias_method, :checking_return_value, :public_one).should equal(@class)
+  describe "returned value" do
+    ruby_version_is ""..."3.0" do
+      it "returns self" do
+        @class.send(:alias_method, :checking_return_value, :public_one).should equal(@class)
+      end
+    end
+
+    ruby_version_is "3.0" do
+      it "returns symbol of the defined method name" do
+        @class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value)
+        @class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value)
+      end
+    end
   end
 
   it "works in module" do
diff --git a/vm_method.c b/vm_method.c
index 9ee9688..1546722 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -1941,13 +1941,13 @@ rb_alias(VALUE klass, ID alias_name, ID original_name) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1941
 
 /*
  *  call-seq:
- *     alias_method(new_name, old_name)   -> self
+ *     alias_method(new_name, old_name)   -> symbol
  *
  *  Makes <i>new_name</i> a new copy of the method <i>old_name</i>. This can
  *  be used to retain access to methods that are overridden.
  *
  *     module Mod
- *       alias_method :orig_exit, :exit
+ *       alias_method :orig_exit, :exit #=> :orig_exit
  *       def exit(code=0)
  *         puts "Exiting with code #{code}"
  *         orig_exit(code)
@@ -1968,8 +1968,9 @@ rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1968
     if (!oldid) {
 	rb_print_undef_str(mod, oldname);
     }
-    rb_alias(mod, rb_to_id(newname), oldid);
-    return mod;
+    VALUE id = rb_to_id(newname);
+    rb_alias(mod, id, oldid);
+    return ID2SYM(id);
 }
 
 static void
-- 
cgit v0.10.2


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

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