diff options
author | Jonathan Hefner <[email protected]> | 2022-10-11 12:02:15 -0500 |
---|---|---|
committer | git <[email protected]> | 2022-10-15 00:08:44 +0900 |
commit | 60610031009e60bdfe5775b0316df251ee36a973 (patch) | |
tree | 9c9c2e8f77186cf2e30ea32431037bb00e52984c /lib/delegate.rb | |
parent | d4162053410782a449e0921ee7222e7ce3deca6f (diff) |
[ruby/delegate] Fix DelegateClass block "method redefined" warning
This commit prevents "method redefined" warnings when overriding methods
within a `DelegateClass` block, such as in the following example:
```ruby
Base = Class.new do
def foo
"foo"
end
end
Overridden = DelegateClass(Base) do
def foo
super + "!"
end
end
```
Fixes https://bugs.ruby-lang.org/issues/19047.
https://github.com/ruby/delegate/commit/214fae86de
Diffstat (limited to 'lib/delegate.rb')
-rw-r--r-- | lib/delegate.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb index 70d4e4ad1d..af95c866f3 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -412,10 +412,12 @@ def DelegateClass(superclass, &block) end protected_instance_methods.each do |method| define_method(method, Delegator.delegating_block(method)) + alias_method(method, method) protected method end public_instance_methods.each do |method| define_method(method, Delegator.delegating_block(method)) + alias_method(method, method) end end klass.define_singleton_method :public_instance_methods do |all=true| |