Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DelegateClass block "method redefined" warning #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,12 @@ def __setobj__(obj) # :nodoc:
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|
Expand Down
12 changes: 12 additions & 0 deletions test/test_delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def test_delegate_class_block
assert_equal(1, klass.new([1]).foo)
end

def test_delegate_class_block_with_override
warning = EnvUtil.verbose_warning do
klass = DelegateClass(Array) do
def first
super.inspect
end
end
assert_equal("1", klass.new([1]).first)
end
assert_empty(warning)
end

def test_systemcallerror_eq
e = SystemCallError.new(0)
assert((SimpleDelegator.new(e) == e) == (e == SimpleDelegator.new(e)), "[ruby-dev:34808]")
Expand Down