Ruby Operator Reference

The table below lists all of Ruby’s operators in descending order of precedence. Operators that are implemented as methods may be overridden and are indicated in the Method? column with an X.

Table 1. Ruby’s operators
Operator(s) Description Method
!, ~, + Boolean NOT, bitwise complement, unary plus X
** Exponentiation X
- Unary minus X
*, /, % Multiplication, division, modulo (remainder) X
+, - Addition (or concatenation), subtraction X
<<, >> Bitwise shift-left (append), bitwise shift-right X
& Bitwise AND X
|, ^ Bitwise OR, bitwise exclusive OR X
>, >=, <, <= Greater than, (or equal to), less than, (or equal to) X
<=>, ==, ===, !=, =~, !~ Equality comparison (spaceship, equality, equality, not equal to, match, not match) X
&& Boolean AND  
|| Boolean OR  
.., ... Range inclusive (..), range exclusive (...) X (not ...)
=, +=, -+, *=, /=, %=, **=, <<=, >>=, &=, |=, ^=, &&= Assignment (=), all others abbreviated assignment  
not Logical negation  
and, or Logical composition  
defined? Tests variable definition and type