From 836c1700104c305fa13cbc7b17d114705dd807b2 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 9 Feb 2026 13:45:34 -0500 Subject: Fix UnboundMethod#== for methods from included/extended modules Method#unbind clones the method entry, preserving its defined_class. For methods mixed in via include/extend, defined_class is an ICLASS, causing UnboundMethod#== to return false when comparing against the same method obtained via Module#instance_method. Resolve ICLASS defined_class in method_eq. Fixes [Bug #21873] --- test/ruby/test_method.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/ruby/test_method.rb') diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 8561f841a8..c3819cdebf 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -111,6 +111,20 @@ class TestMethod < Test::Unit::TestCase end end + def test_unbound_method_equality_with_extended_module + m = Module.new { def hello; "hello"; end } + base = Class.new { extend m } + sub = Class.new(base) + + from_module = m.instance_method(:hello) + from_base = base.method(:hello).unbind + from_sub = sub.method(:hello).unbind + + assert_equal(from_module, from_base) + assert_equal(from_module, from_sub) + assert_equal(from_base, from_sub) + end + def test_callee assert_equal(:test_callee, __method__) assert_equal(:m, Class.new {def m; __method__; end}.new.m) -- cgit v1.2.3