1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

delegate.rb: don't look for methods on Kernel

Instead, look for instance methods of Kernel.
Otherwise, instance methods of Module (which are methods of Kernel
itself) are mistakenly believed to exist, and it fails when calling
Kernel.instance_method().

Closes: https://github.com/ruby/ruby/pull/1422
This commit is contained in:
Étienne Barrié 2016-08-30 13:29:07 -04:00 committed by Nobuyoshi Nakada
parent 24964fff92
commit 2dc613815d
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 8 additions and 1 deletions

View file

@ -81,7 +81,7 @@ class Delegator < BasicObject
if r && target.respond_to?(m)
target.__send__(m, *args, &block)
elsif ::Kernel.respond_to?(m, true)
elsif ::Kernel.method_defined?(m) || ::Kernel.private_method_defined?(m)
::Kernel.instance_method(m).bind(self).(*args, &block)
else
super(m, *args, &block)

View file

@ -258,4 +258,11 @@ class TestDelegateClass < Test::Unit::TestCase
def test_dir_in_delegator_class
assert_equal(__dir__, Bug9403::DC.dir_name, Bug9403::Name)
end
def test_module_methods_vs_kernel_methods
delegate = SimpleDelegator.new(Object.new)
assert_raise(NoMethodError) do
delegate.constants
end
end
end