From: "joel@... (Joel Drapper)" Date: 2022-09-11T10:45:59+00:00 Subject: [ruby-core:109887] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes Issue #18798 has been updated by joel@drapper.me (Joel Drapper). This would be really helpful for checking if a class has redefined a method inherited form a superclass. As an example, I���m working on a compiler that replaces certain method calls with their inlined expected behaviour from an abstract superclass. Because it's possible for the subclass to override these abstract methods, the compiler should check if `instance_method(name) == AbstractClass.instance_method(name)` before folding it. While this wouldn't cover the method being overridden in the singleton class, that's a reasonable concession for my specific use case. ---------------------------------------- Feature #18798: `UnboundMethod#==` with inherited classes https://bugs.ruby-lang.org/issues/18798#change-99128 * Author: ko1 (Koichi Sasada) * Status: Open * Priority: Normal ---------------------------------------- Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`. ```ruby class C def foo = :C $mc = instance_method(:foo) end class D < C $md = instance_method(:foo) end p $mc == $md #=> false p $mc.owner #=> C p $mc.owner == $md.owner #=> true p $mc.source_location == $md.source_location #=> true p $mc.inspect #=> "#" p $md.inspect #=> "#" ``` How about to make it `UnboundMethod#==` return true for this case? Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple. FYI: On aliased unbound methods point to a same method are `==`. ```ruby class C def foo = :C alias bar foo $mfoo = instance_method(:foo) $mbar = instance_method(:bar) end p $mfoo, $mbar #=> # #=> # p $mfoo == $mbar #=> true ``` -- https://bugs.ruby-lang.org/ Unsubscribe: