Operators
Table 2 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.
Table 2. Ruby’s operators
Operator | Description | Method |
|---|---|---|
| Scope resolution | |
| Reference, set | ✓ |
| Raise to power (exponentiation) | ✓ |
| Positive (unary), negative (unary), logical negation, complement | ✓ (not |
| Multiplication, division, modulo (remainder) | ✓ |
| Addition, subtraction | ✓ |
| Shift left, shift right | ✓ |
| Bitwise and | ✓ |
| Bitwise or, bitwise exclusive or | ✓ |
| Greater than, greater than or equal to, less than, less than or equal to | ✓ |
| Equality comparison (spaceship, equality, equality, not equal to, match, not match | ✓ (not |
| Logical and | |
| Logical or | |
| Range inclusive, range exclusive | ✓ (not |
| Ternary | |
| Assignment, abbreviated assignment | |
| Logical negation | |
| Logical composition | |
| Special operator (no precedence) |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access