2013-01-15 08:33:28 +04:00
|
|
|
= Precedence
|
|
|
|
|
|
|
|
From highest to lowest, this is the precedence table for ruby. High precedence
|
|
|
|
operations happen before low precedence operations.
|
|
|
|
|
|
|
|
!, ~, unary +
|
|
|
|
|
|
|
|
**
|
|
|
|
|
|
|
|
unary -
|
|
|
|
|
|
|
|
*, /, %
|
|
|
|
|
|
|
|
+, -
|
|
|
|
|
|
|
|
<<, >>
|
|
|
|
|
|
|
|
&
|
|
|
|
|
|
|
|
|, ^
|
|
|
|
|
|
|
|
>, >=, <, <=
|
|
|
|
|
|
|
|
<=>, ==, ===, !=, =~, !~
|
|
|
|
|
|
|
|
&&
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
.., ...
|
|
|
|
|
|
|
|
?, :
|
|
|
|
|
|
|
|
modifier-rescue
|
|
|
|
|
|
|
|
=, +=, -=, etc.
|
|
|
|
|
|
|
|
defined?
|
|
|
|
|
|
|
|
not
|
|
|
|
|
|
|
|
or, and
|
|
|
|
|
|
|
|
modifier-if, modifier-unless, modifier-while, modifier-until
|
|
|
|
|
|
|
|
{ } blocks
|
|
|
|
|
|
|
|
Unary <code>+</code> and unary <code>-</code> are for <code>+1</code>,
|
|
|
|
<code>-1</code> or <code>-(a + b)</code>.
|
|
|
|
|
|
|
|
Modifier-if, modifier-unless, etc. are for the modifier versions of those
|
2019-10-10 21:25:54 +03:00
|
|
|
keywords. For example, this is a modifier-unless statement:
|
2013-01-15 08:33:28 +04:00
|
|
|
|
|
|
|
a += 1 unless a.zero?
|
|
|
|
|
2019-10-10 21:25:54 +03:00
|
|
|
Note that <code>(a if b rescue c)</code> is parsed as <code>((a if b) rescue
|
|
|
|
c)</code> due to reasons not related to precedence. See {modifier
|
2022-02-09 09:31:10 +03:00
|
|
|
statements}[control_expressions.rdoc#label-Modifier+Statements].
|
2019-10-10 21:25:54 +03:00
|
|
|
|
2013-01-15 08:33:28 +04:00
|
|
|
<code>{ ... }</code> blocks have priority below all listed operations, but
|
|
|
|
<code>do ... end</code> blocks have lower priority.
|
|
|
|
|
|
|
|
All other words in the precedence table above are keywords.
|
|
|
|
|