From 26e88e1e4a1849d65f19b9714fa802d76ceae9f7 Mon Sep 17 00:00:00 2001 From: Sampo Kuokkanen Date: Mon, 4 May 2026 20:28:49 +0900 Subject: [PATCH] Add specs for Method#/UnboundMethod#original_name through a three-alias chain Extend MethodSpecs::Methods and UnboundMethodSpecs::Methods with a third alias hop (alias qux baz), and add examples verifying that Method#original_name and UnboundMethod#original_name still return :foo when reached through three levels of aliasing. The existing "aliased twice" examples only exercise two-hop chains, which doesn't catch implementations that resolve a fixed depth rather than walking the full chain. --- core/method/fixtures/classes.rb | 1 + core/method/original_name_spec.rb | 6 ++++++ core/unboundmethod/fixtures/classes.rb | 1 + core/unboundmethod/original_name_spec.rb | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/core/method/fixtures/classes.rb b/core/method/fixtures/classes.rb index 464a519aea..41904df1d1 100644 --- a/core/method/fixtures/classes.rb +++ b/core/method/fixtures/classes.rb @@ -27,6 +27,7 @@ def foo alias bar foo alias baz bar + alias qux baz def same_as_foo true diff --git a/core/method/original_name_spec.rb b/core/method/original_name_spec.rb index 71cfb65656..8fec0e7c33 100644 --- a/core/method/original_name_spec.rb +++ b/core/method/original_name_spec.rb @@ -20,6 +20,12 @@ obj.method(:baz).unbind.bind(obj).original_name.should == :foo end + it "returns the original name even when aliased thrice" do + obj = MethodSpecs::Methods.new + obj.method(:qux).original_name.should == :foo + obj.method(:qux).unbind.bind(obj).original_name.should == :foo + end + it "returns the source UnboundMethod's name (not the name given to define_method)" do klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) } klass.new.method(:my_inspect).original_name.should == :inspect diff --git a/core/unboundmethod/fixtures/classes.rb b/core/unboundmethod/fixtures/classes.rb index bb3f7e0849..58120c2f88 100644 --- a/core/unboundmethod/fixtures/classes.rb +++ b/core/unboundmethod/fixtures/classes.rb @@ -36,6 +36,7 @@ def with_block(&block); end alias bar foo alias baz bar + alias qux baz alias alias_1 foo alias alias_2 foo diff --git a/core/unboundmethod/original_name_spec.rb b/core/unboundmethod/original_name_spec.rb index e50ce28dd7..fa9a6fcc63 100644 --- a/core/unboundmethod/original_name_spec.rb +++ b/core/unboundmethod/original_name_spec.rb @@ -20,6 +20,12 @@ UnboundMethodSpecs::Methods.instance_method(:baz).original_name.should == :foo end + it "returns the original name even when aliased thrice" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:qux).unbind.original_name.should == :foo + UnboundMethodSpecs::Methods.instance_method(:qux).original_name.should == :foo + end + it "returns the source UnboundMethod's name (not the name given to define_method)" do klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) } klass.instance_method(:my_inspect).original_name.should == :inspect