Your problem occurs at:
params[:id] == '2' || params.has_key? :id
which can be simplified to:
:foo || some_method :bar
which causes the same error. This expression is in principle ambiguous between
(:foo || some_method) :bar (1)
and
:foo || (some_method :bar) (2)
When an expression is ambiguous, it is resolved by other factors. One of the factors, the priority of the operator does not say anything about the ambiguity between (1) and (2). The next factor is the linear order. Since || appears before the application () argument (omitted) in the expression in question, the former is applied before the latter. Therefore, the expression is interpreted as (1). Since (:foo || some_method) then parsed as an expression, there will be two expressions next to it. This is not grammatical, just like:
:baz :bar
is non-grammatical.
In fact, if you change the order as follows:
some_method :bar || :foo
then it will be interpreted as
(some_method :bar) || :foo
for the same reason, and the syntax error will disappear.
Also, when you resolve ambiguity, explicitly using parentheses to indicate the application of the argument:
:foo || some_method(:bar)
then there is no ambiguity to be resolved, and the syntax error disappears.
source share