Previous answers
The answer to a similar question is wrong.
Method calls are mentionned neither in Ruby documentation nor in the community wiki.
Method call without parentheses
Higher than or
or seems to have a lower precedence than a method call without parentheses :
puts false or true
is equivalent to
( puts false ) or true
and displays false.
NOTE: I know or shouldn't be used. Still, it's a good example to show that some operators do have lower precedence than method calls.
Lower than ||
puts false || true
is equivalent to
puts (false || true)
and displays true.
Method call with parentheses
The parentheses used for method call don't seem to be grouping :
puts(false or true)
# SyntaxError: unexpected keyword_or
puts((false or true))
#=> true
Question
Where should method calls with and without parentheses be in this precedence table?
Bounty clarification
I'm looking for the exact location of method calls in the table. Preferably with examples proving it's lower than the previous one and higher than the next one.
The current answers also don't seem to mention method calls with parentheses.
Thanks in advance!
Prelude
This aims to test all possible scenarios.
Note that when saying "operator
Xhas higher precedence than method invocation" what is meant is in arguments. Aka:as opposed to (call on object)
As far as the second case is concerned, method calls always have higher precedence.
Short answer
It doesn't fit:
SyntaxErrorin some casesrescue, but lower than assignmentSummary
notcan't be used after method invocation regardless of brackets()) with method invocations sometimes causes aSyntaxError. These cases are:and,or,if,unless,until,whileandrescueand,or, postfixif,unless,until,while,rescuehave higher precedence than method invocationLets try it:
First unary:
Points taken:
notafter a method invocation is aSyntaxErrorNow binary:
Points taken:
andororis aSyntaxErrorandandorfurther without brackets..and...call<=>. We have to test this further&&,||,==,!=, modifierrescue,if,unless,until,whilePoints taken:
andandorhave lower precedence without brackets&&,||,==and!=have higher precedence regardless of bracketsPoints taken:
..and...have higher precedence regardless of bracketsPoints taken:
if,unless,until,whilecause aSyntaxErrorPoints taken:
rescuecause aSyntaxErrorrescuehas lower precedence if no brackets are presentTernary:
Points taken:
Assignment (left for last as it changes
yesandno):Points taken:
Note that
+=and the like are just shortcuts for+and=so they exhibit the same behaviour.