From 7de060b649da1414f0670057776298e175b84647 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 19 Feb 2021 16:42:40 +0900 Subject: [PATCH] Get rid of YARD error --- lib/rspec/mocks/verifying_double.rb | 41 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/rspec/mocks/verifying_double.rb b/lib/rspec/mocks/verifying_double.rb index 5980d5132..3e7c3ec2b 100644 --- a/lib/rspec/mocks/verifying_double.rb +++ b/lib/rspec/mocks/verifying_double.rb @@ -21,29 +21,36 @@ def respond_to?(message, include_private=false) # Get rid of calling overridden `method_missing` missing_method = ::BasicObject.instance_method(:method_missing) - unless missing_method.respond_to?(:bind_call) # < Ruby 2.7 - def missing_method.bind_call(receiver, *args, &block) - bind(receiver).call(*args, &block) + class << missing_method + unless method_defined?(:bind_call) # < Ruby 2.7 + # @private + def bind_call(receiver, *args, &block) + bind(receiver).call(*args, &block) + end end - end - # Tell whether the method call which caused `method_missing` - # was called in the private or public form, by using - # `NoMethodError#private_call?`. - def missing_method.private_call?(object, message) - bind_call(object, message) - rescue NoMethodError => e - e.private_call? - rescue NameError # without receiver, arguments and parentheses - true - else # should not happen - false + # Tell whether the method call which caused `method_missing` + # was called in the private or public form, by using + # `NoMethodError#private_call?`. + # @private + def private_call?(object, message) + bind_call(object, message) + rescue NoMethodError => e + e.private_call? + rescue NameError # without receiver, arguments and parentheses + true + else # should not happen + false + end end else missing_method = (defined?(::BasicObject) ? ::BasicObject : ::Object).new - def missing_method.private_call?(object, message) - object.instance_variable_get(:@__sending_message) == message + class << missing_method + # @private + def private_call?(object, message) + object.instance_variable_get(:@__sending_message) == message + end end # Redefining `__send__` causes ruby to issue a warning.