Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem is happening at:</p> <pre><code>params[:id] == '2' || params.has_key? :id </code></pre> <p>which can be simplified to:</p> <pre><code>:foo || some_method :bar </code></pre> <p>which causes the same error. This expression is in principle, ambiguous between</p> <pre><code>(:foo || some_method) :bar (1) </code></pre> <p>and</p> <pre><code>:foo || (some_method :bar) (2) </code></pre> <p>When an expression is ambiguous, it is resolved by other factors. One factor, operator precedence tells nothing here about disambiguating between (1) and (2). The next factor is linear order. Since <code>||</code> appears before argument application <code>()</code> (omitted) in the expression in question, the former applies before the latter. Therefore, the expression is interpreted as (1). Since <code>(:foo || some_method)</code> would then be parsed as an expression, there would be two expressions next to each other. That is ungrammatical, just as:</p> <pre><code>:baz :bar </code></pre> <p>is ungrammatical.</p> <p>In fact, if you switch the order as:</p> <pre><code>some_method :bar || :foo </code></pre> <p>then, it will be interpreted as</p> <pre><code>(some_method :bar) || :foo </code></pre> <p>for the same reason, and syntax error will disappear.</p> <p>Also when you resolve ambiguity by explicitly using parentheses to indicate argument application:</p> <pre><code>:foo || some_method(:bar) </code></pre> <p>then there is no ambiguity needed to be resolved, and the syntax error disappears.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload