From: "mame (Yusuke Endoh)" Date: 2022-10-06T14:29:18+00:00 Subject: [ruby-core:110209] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes Issue #18798 has been updated by mame (Yusuke Endoh). > No class field anymore: > > ``` > # > # (no visual difference) > true > [#, #] > ``` This understanding is correct. Discussed at the dev meeting. To the best of our knowledge, the receiver of instance_method is now only used in `UnboundMethod#inspect` (and `#to_s`). At the dev meeting, no one saw the significance of keeping track of this receiver. So @matz wants to discard the information and to change `#==`, `#eql?`, `#hash` (if needed), `#inspect`, and `#to_s` as you said. ---------------------------------------- Feature #18798: `UnboundMethod#==` with inherited classes https://bugs.ruby-lang.org/issues/18798#change-99492 * 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: