From: josh@... Date: 2021-03-16T18:15:49+00:00 Subject: [ruby-core:102886] [Ruby master Bug#17725] Prepend Breaks Ability to Alias Issue #17725 has been updated by joshuadreed (Josh Reed). So, I set out to test my hypothesis regarding refinements. I've never used refinements prior to this, so it's still possible there's an interaction somewhere, but at least not in the way I was thinking. ``` ruby module Dummy; end class Foo def ten 10 end end module Bar refine Foo do def ten 11 end end end class Baz using Bar def check Foo.new.ten end end Baz.prepend(Dummy) class Baz alias_method(:old_check, :check) def check puts 'blah blah' old_check end end p Baz.new.check >blah blah >11 ``` ---------------------------------------- Bug #17725: Prepend Breaks Ability to Alias https://bugs.ruby-lang.org/issues/17725#change-90946 * Author: joshuadreed (Josh Reed) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- Prepending any module to `String` and `Hash` (and possibly other or all classes?) blocks the ability to `alias` As an example: ``` ruby module Dummy; end # String.prepend(Dummy) class String alias_method(:old_plus, :+) def + other puts 'blah blah' old_plus(other) end end 'a' + 'b' > blah blah ``` ``` ruby module Dummy; end String.prepend(Dummy) class String alias_method(:old_plus, :+) def + other puts 'blah blah' old_plus(other) end end 'a' + 'b' > ``` Prepending after an `alias` does not affect the previous `alias` -- https://bugs.ruby-lang.org/ Unsubscribe: