Rubocop gives me the following offence
lib/daru/vector.rb:1182:5: C: Style/MethodMissing: When using method_missing, define respond_to_missing? and fall back on super.
def method_missing(name, *args, &block) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method missing is defined as:
def method_missing(name, *args, &block)
if name =~ /(.+)\=/
self[$1.to_sym] = args[0]
elsif has_index?(name)
self[name]
else
super(name, *args, &block)
end
end
I tried fixing it with the below code sighting an example from here
def respond_to_missing?(method_name, include_private=false)
(name =~ /(.+)\=/) || has_index?(name) || super
end
But now Rubocop give me the follow offence:
lib/daru/vector.rb:1182:5: C: Style/MethodMissing: When using method_missing, fall back on super.
def method_missing(name, *args, &block) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I can't seem to figure out what's wrong. As you can see I'm falling back on super in the else block.
Rubocop expects super
to be called without arguments. As the arguments you are passing to super
are the same as those you received, you can simply remove the arguments:
def method_missing(name, *args, &block)
if name =~ /(.+)\=/
self[$1.to_sym] = args[0]
elsif has_index?(name)
self[name]
else
super
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With