What does "(...) interpreted as grouped expression" mean?

11.2k views Asked by At

I'm using a Ruby linter in Atom and for some lines it gives the following warning:

(...) interpreted as grouped expression

An example of a line that get's this warning is this:

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

How should that line be improved to make the warning go away?

3

There are 3 answers

1
Jörg W Mittag On BEST ANSWER

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.

0
rocky On

The warning I get is from from MRI Ruby itself (with options -wc), and I think you have a typo in there. The message I get doesn't have the word "grounded" but "grouped".

Parenthesis in Ruby can be used for one of two things, to group expressions or to mark the argument list of a function or method.

What that error message is saying is that of these two options, Ruby is treating it like an expression. Note that it in Ruby is possible for you to define a method called "not".

And In this particular case it doesn't matter which way Ruby interprets the parenthesis.

One way to get rid of the message is to remove the space between "not (". If you think this is screwy, I agree with you.

0
Mourad On

Try to Remove the space between not and the parenthesis