Skip to content

Commit 5a19c23

Browse files
authored
Merge pull request #13 from jonathanhefner/delegate_class-block-method-redefined-warning
Fix `DelegateClass` block "method redefined" warning
2 parents df2283b + 214fae8 commit 5a19c23

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/delegate.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,12 @@ def __setobj__(obj) # :nodoc:
412412
end
413413
protected_instance_methods.each do |method|
414414
define_method(method, Delegator.delegating_block(method))
415+
alias_method(method, method)
415416
protected method
416417
end
417418
public_instance_methods.each do |method|
418419
define_method(method, Delegator.delegating_block(method))
420+
alias_method(method, method)
419421
end
420422
end
421423
klass.define_singleton_method :public_instance_methods do |all=true|

test/test_delegate.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ def test_delegate_class_block
2929
assert_equal(1, klass.new([1]).foo)
3030
end
3131

32+
def test_delegate_class_block_with_override
33+
warning = EnvUtil.verbose_warning do
34+
klass = DelegateClass(Array) do
35+
def first
36+
super.inspect
37+
end
38+
end
39+
assert_equal("1", klass.new([1]).first)
40+
end
41+
assert_empty(warning)
42+
end
43+
3244
def test_systemcallerror_eq
3345
e = SystemCallError.new(0)
3446
assert((SimpleDelegator.new(e) == e) == (e == SimpleDelegator.new(e)), "[ruby-dev:34808]")

0 commit comments

Comments
 (0)