Operators Precedence Table

(High to low precedence)

Operator Description
[ ] [ ]= Element reference, element set
**
Exponentiation
irb(main):002:0> 2 ** 3 => 8
! ~ + - Not, complement, unary plus and minus (method names for the last two are +@ and -@)
* / %
Multiply, divide, and modulo
+ - Plus and minus
» « Right and left shift
& Bitwise 'and'
^ |
Bitwise exclusive `or' and regular `or'
<= < > >=
Comparison operators
<=> == === != =~ !~
Equality and pattern match operators (!= and !~ may not be defined as methods)
&& Logical 'and'
||
Logical 'or'
.. … Range (inclusive and exclusive)
? : Ternary if-then-else
= %= { /= -= += |= &= >>= <<= *= &&= ||= **=
Assignment
defined? Check if symbol defined
not Logical negation
or and Logical composition
if unless while until Expression modifiers
begin/end Block expression

From: Programming Ruby - The Pragmatic Programmer's Guide


Personal Tools