[ruby-core:102911] [Ruby master Bug#17725] Prepend breaks ability to override optimized methods
From:
xtkoba+ruby@...
Date:
2021-03-18 04:35:49 UTC
List:
ruby-core #102911
Issue #17725 has been updated by xtkoba (Tee KOBAYASHI).
FWIW,
```ruby
# bug17725-test.rb
eval <<EOS
# encoding: ascii-8bit
MY_STRING = ''
EOS
MY_STRING + ''
String.prepend(Module.new)
class String
def + other
'blah blah'
end
end
p 'a' + 'b'
```
gives
```
$ ruby --disable-gems bug17725-test.rb
"ab"
```
----------------------------------------
Bug #17725: Prepend breaks ability to override optimized methods
https://bugs.ruby-lang.org/issues/17725#change-90975
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>