Ruby on rails Lint/AmbiguousOperator:不明确的负数运算符
我用的是宝石。 下面是我的factorybot代码Ruby on rails Lint/AmbiguousOperator:不明确的负数运算符,ruby-on-rails,ruby,rubocop,Ruby On Rails,Ruby,Rubocop,我用的是宝石。 下面是我的factorybot代码 factory :cut, class: CutSetting do maximum_length 100 max_colors_cut_together -1 end Rubocop给出负值-1的以下错误 factory :cut, class: CutSetting do maximum_length 100 max_colors_cut_together -1 end Lint/AmbiguousOperato
factory :cut, class: CutSetting do
maximum_length 100
max_colors_cut_together -1
end
Rubocop给出负值-1的以下错误
factory :cut, class: CutSetting do
maximum_length 100
max_colors_cut_together -1
end
Lint/AmbiguousOperator:不明确的负数运算符。如果方法参数肯定是负数运算符,请将其插入括号;如果应该是减法运算符,请在-的右侧添加空格。()
factory :cut, class: CutSetting do
maximum_length 100
max_colors_cut_together -1
end
如何解决这个问题。请帮帮我
factory :cut, class: CutSetting do
maximum_length 100
max_colors_cut_together -1
end
提前感谢。我不能再补充Rubocop的错误描述了,它清晰而全面。将括号添加到-1:
factory :cut, class: CutSetting do
maximum_length 100
max_colors_cut_together -1
end
max_colors_cut_together { -1 }
应该消除这个错误
factory :cut, class: CutSetting do
maximum_length 100
max_colors_cut_together -1
end
这是关于工厂机器人模式的快速指南。
max\u colors\u cut\u-together-1实际上是ruby方法调用的语法糖max\u colors\u cut\u-together(-1)
非常感谢。llya Konyukhov和您的答案都有效。请注意,FactoryBot中不推荐使用静态属性。在下一个版本中,您需要在所有值周围使用括号{}
。
factory :cut, class: CutSetting do
maximum_length 100
max_colors_cut_together -1
end