Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Lint/AmbiguousOperator:不明确的负数运算符_Ruby On Rails_Ruby_Rubocop - Fatal编程技术网

Ruby on rails Lint/AmbiguousOperator:不明确的负数运算符

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

我用的是宝石。 下面是我的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/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