mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
rubocop: fix offences of the Style/MethodMissingSuper cop
This commit is contained in:
parent
082691eb90
commit
0c0b171486
10 changed files with 57 additions and 39 deletions
|
@ -197,14 +197,3 @@ Style/FormatStringToken:
|
|||
Style/GlobalVars:
|
||||
Exclude:
|
||||
- 'spec/commands/edit_spec.rb'
|
||||
|
||||
# Offense count: 7
|
||||
Style/MethodMissingSuper:
|
||||
Exclude:
|
||||
- 'lib/pry/code.rb'
|
||||
- 'lib/pry/config/behavior.rb'
|
||||
- 'lib/pry/method.rb'
|
||||
- 'lib/pry/method/disowned.rb'
|
||||
- 'lib/pry/output.rb'
|
||||
- 'lib/pry/plugins.rb'
|
||||
- 'lib/pry/wrapped_module.rb'
|
||||
|
|
|
@ -331,14 +331,18 @@ class Pry
|
|||
end
|
||||
|
||||
# Forward any missing methods to the output of `#to_s`.
|
||||
def method_missing(name, *args, &block)
|
||||
to_s.send(name, *args, &block)
|
||||
def method_missing(method_name, *args, &block)
|
||||
if (string = to_s).respond_to?(method_name)
|
||||
string.__send__(method_name, *args, &block)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
undef =~
|
||||
|
||||
# Check whether String responds to missing methods.
|
||||
def respond_to_missing?(name, include_all = false)
|
||||
''.respond_to?(name, include_all)
|
||||
def respond_to_missing?(method_name, include_private = false)
|
||||
''.respond_to?(method_name, include_private) || super
|
||||
end
|
||||
|
||||
if RUBY_VERSION.start_with?('1.9')
|
||||
|
|
|
@ -317,18 +317,20 @@ class Pry
|
|||
q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
key = name.to_s
|
||||
if key[-1] == ASSIGNMENT
|
||||
short_key = key[0..-2]
|
||||
self[short_key] = args[0]
|
||||
elsif key?(key)
|
||||
self[key]
|
||||
elsif @default.respond_to?(name)
|
||||
value = @default.public_send(name, *args, &block)
|
||||
self[key] = __dup(value)
|
||||
# rubocop:disable Style/MethodMissingSuper
|
||||
def method_missing(method_name, *args, &block)
|
||||
name = method_name.to_s
|
||||
if name[-1] == ASSIGNMENT
|
||||
short_name = name[0..-2]
|
||||
self[short_name] = args[0]
|
||||
elsif key?(name)
|
||||
self[name]
|
||||
elsif @default.respond_to?(method_name)
|
||||
value = @default.public_send(method_name, *args, &block)
|
||||
self[name] = __dup(value)
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/MethodMissingSuper
|
||||
|
||||
def respond_to_missing?(key, include_all = false)
|
||||
key = key.to_s.chomp(ASSIGNMENT)
|
||||
|
|
|
@ -493,7 +493,11 @@ class Pry
|
|||
|
||||
# Delegate any unknown calls to the wrapped method.
|
||||
def method_missing(method_name, *args, &block)
|
||||
@method.send(method_name, *args, &block)
|
||||
if @method.respond_to?(method_name)
|
||||
@method.__send__(method_name, *args, &block)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def respond_to_missing?(method_name, include_private = false)
|
||||
|
|
|
@ -46,14 +46,16 @@ class Pry
|
|||
end
|
||||
|
||||
# Raise a more useful error message instead of trying to forward to nil.
|
||||
def method_missing(meth_name, *args, &block)
|
||||
if method(:name).respond_to?(meth_name)
|
||||
raise "Cannot call '#{meth_name}' on an undef'd method."
|
||||
# rubocop:disable Style/MethodMissingSuper
|
||||
def method_missing(method_name, *args, &block)
|
||||
if method(:name).respond_to?(method_name)
|
||||
raise "Cannot call '#{method_name}' on an undef'd method."
|
||||
end
|
||||
|
||||
Object.instance_method(:method_missing).bind(self)
|
||||
.call(meth_name, *args, &block)
|
||||
method = Object.instance_method(:method_missing).bind(self)
|
||||
method.call(method_name, *args, &block)
|
||||
end
|
||||
# rubocop:enable Style/MethodMissingSuper
|
||||
|
||||
def respond_to_missing?(method_name, include_private = false)
|
||||
!method(:name).respond_to?(method_name) || super
|
||||
|
|
|
@ -33,8 +33,12 @@ class Pry
|
|||
@boxed_io.respond_to?(:tty?) && @boxed_io.tty?
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
@boxed_io.__send__(name, *args, &block)
|
||||
def method_missing(method_name, *args, &block)
|
||||
if @boxed_io.respond_to?(method_name)
|
||||
@boxed_io.__send__(method_name, *args, &block)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def respond_to_missing?(m, include_all = false)
|
||||
|
|
|
@ -8,8 +8,9 @@ class Pry
|
|||
@name = name
|
||||
end
|
||||
|
||||
def method_missing(*_args)
|
||||
def method_missing(*)
|
||||
warn "Warning: The plugin '#{@name}' was not found! (no gem found)"
|
||||
super
|
||||
end
|
||||
|
||||
def respond_to_missing?(*)
|
||||
|
|
|
@ -567,7 +567,7 @@ class Pry
|
|||
|
||||
unless @prompt_warn
|
||||
@prompt_warn = true
|
||||
output.warn(
|
||||
warn(
|
||||
"warning: setting prompt with help of " \
|
||||
"`Pry.config.prompt = [proc {}, proc {}]` is deprecated. " \
|
||||
"Use Pry::Prompt API instead"
|
||||
|
|
|
@ -146,7 +146,11 @@ class Pry
|
|||
|
||||
# Forward method invocations to the wrapped module
|
||||
def method_missing(method_name, *args, &block)
|
||||
wrapped.send(method_name, *args, &block)
|
||||
if wrapped.respond_to?(method_name)
|
||||
wrapped.send(method_name, *args, &block)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def respond_to_missing?(method_name, include_private = false)
|
||||
|
|
|
@ -501,9 +501,17 @@ RSpec.describe Pry::Code do
|
|||
end
|
||||
|
||||
describe "#method_missing" do
|
||||
it "forwards any missing methods to the output of '#to_s'" do
|
||||
expect(subject).to receive_message_chain(:to_s, :send)
|
||||
subject.abcdefg
|
||||
context "when a String responds to the given method" do
|
||||
it "forwards the method to a String instance" do
|
||||
expect(subject.upcase).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
context "when a String does not respond to the given method" do
|
||||
it "raises NoMethodError" do
|
||||
expect { subject.abcdefg }
|
||||
.to raise_error(NoMethodError, /undefined method `abcdefg'/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue