From: "ko1 (Koichi Sasada)" Date: 2022-12-06T09:13:04+00:00 Subject: [ruby-core:111219] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes Issue #18798 has been updated by ko1 (Koichi Sasada). Status changed from Open to Closed https://github.com/ruby/ruby/pull/6855 was merged. `p String.instance_method(:object_id) == Array.instance_method(:object_id) #=> true` ---------------------------------------- Feature #18798: `UnboundMethod#==` with inherited classes https://bugs.ruby-lang.org/issues/18798#change-100509 * Author: ko1 (Koichi Sasada) * Status: Closed * 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/