I tried code like this in ruby:
if object && object.is? ball
object.throw!
end
This resulted in a syntax error:
unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
I figure this is because && must have a higher "precedence" than a function call (I'm sorry, I don't know the correct terminology) and so Ruby essentially saw the statement as:
if (object && object.is?) ball
object.throw!
end
which makes no sense and so a syntax error is in order.
This is further supported by the fact that this DOES work:
if object and object.is? ball
object.throw!
end
I presume it is because the 'and' operator has a lower precedence than &&, so the "precedence" of a function call must be somewhere between && and 'and'.
However, in the precedence order tables I have seen before, function calls are not listed.
I would appreciate some insight into what is happening here, and perhaps some references to the ruby specification. I am not an expert in expression resolution, I am just interested in learning more about the processes, problems and theory behind this example of, no doubt, a wider topic