“(...)被解释为分组表达”是什么意思?

时间:2015-06-25 09:10:40

标签: ruby lint

我在Atom中使用Ruby linter,对于某些行,它会发出以下警告:

(...) interpreted as grouped expression

获得此警告的一行示例如下:

elsif not (params[:vacancy].nil? or params[:vacancy]['company_id'].nil? or params[:vacancy]['company_id'] == "0" )

如何改进这条线以使警告消失?

3 个答案:

答案 0 :(得分:15)

The warning is

(...) interpreted as grouped expression

And it means exactly what it says: in Ruby, parentheses can be used for three purposes, expression grouping, parameter lists and argument lists. This warning is emitted when Ruby thinks that you want an argument list but wrote a grouped expression instead. The most common cause is whitespace between the name of the message and the argument list in a message send like this:

foo.bar (1, 2)

This will be interpreted not as an argument list for the message send, but rather a grouped expression, which, in this particular case, is a SyntaxError.

In your particular case, the warning seems to be a false positive.

答案 1 :(得分:5)

Try to Remove the space between not and the parenthesis

答案 2 :(得分:0)

我得到的警告来自MRI Ruby本身(带有选项-wc),我认为你有一个拼写错误。我得到的消息没有“接地”这个词,而是“分组”。

Ruby中的括号可用于以下两种情况之一:组表达式或标记函数或方法的参数列表。

错误信息的含义是,在这两个选项中,Ruby将其视为表达式。请注意,在Ruby中可以定义一个名为“not”的方法。

在这种特殊情况下,Ruby解释括号的方式无关紧要。

消除信息的一种方法是删除“不”之间的空格。如果你认为这很麻烦,我同意你的看法。