Rubocop给了我以下进攻
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) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
缺少的方法定义为:
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
Run Code Online (Sandbox Code Playgroud)
我尝试使用下面的代码修复它,从这里看一个例子
def respond_to_missing?(method_name, include_private=false)
(name =~ /(.+)\=/) || has_index?(name) || super
end
Run Code Online (Sandbox Code Playgroud)
但是现在Rubocop给了我以下进攻:
lib/daru/vector.rb:1182:5: C: Style/MethodMissing: When using method_missing, fall back on super.
def method_missing(name, *args, &block) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚出了什么问题.正如你所看到的那样,我在其他区块中的超级回归.
Rubocop期望super在没有争议的情况下被召唤.由于您传递的参数super与您收到的参数相同,您可以简单地删除参数:
def method_missing(name, *args, &block)
if name =~ /(.+)\=/
self[$1.to_sym] = args[0]
elsif has_index?(name)
self[name]
else
super
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2905 次 |
| 最近记录: |