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:
parent
24964fff92
commit
2dc613815d
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user