From: "matz (Yukihiro Matsumoto) via ruby-core" Date: 2026-11-12T14:26:42+00:00 Subject: [ruby-core:127450] [Ruby Bug#22462] For UnboundMethod, super_method.bind and bind.super_method should return an equal Method Issue #22462 has been updated by matz (Yukihiro Matsumoto). I agree with the proposed invariant: `um.bind(o).super_method == um.super_method.bind(o)`. Please go ahead, on top of the fix for #22505. Regarding the point @shugo raised, I accept that `UnboundMethod#==` and `Method#==` differ here. `UnboundMethod#==` compares method definitions, as decided in #18798. A `Method` is bound to a receiver, so two methods whose `super` chains differ should not be equal. I don't think we need to revisit #18798 for this. Matz. ---------------------------------------- Bug #22462: For UnboundMethod, super_method.bind and bind.super_method should return an equal Method https://bugs.ruby-lang.org/issues/22462#change-119902 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- When a `Method` is created using `UnboundMethod#bind` and `#super_method`, the order in which the `#bind` and `#super_method` were applied could result in `Method` objects that were considered unequal. I believe we should have the invariant: for any `UnboundMethod` `um` where `super_method` is not `nil` and `o` is a valid object to bind to `um`, the following code should be true: ```ruby um.bind(o).super_method == um.super_method.bind(o) ``` However, that didn't work correctly in some cases: ```ruby module M; def m = [:M, *super]; end module N; include M; end class C; def m = :C; end class SC < C include N prepend M def m = [:SC, *super] end o = SC.new um = SC.instance_method(:m).super_method.super_method # M#m below SC (included via N) um.bind(o).super_method == um.super_method.bind(o) # => false # should be true ``` There is a similar invariant for Method: for any `Method` `m` where `super_method` is not `nil`, the following code should be true: ```ruby m.unbind.super_method == m.super_method.unbind ``` This appears to already hold, as the existing refinement tests already checked for this behavior. I've submitted a PR to fix this issue: https://github.com/ruby/ruby/pull/19474 -- 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/lists/ruby-core.ml.ruby-lang.org/