Skip to content

Operators

datanorris edited this page Jan 22, 2016 · 25 revisions

Class-defined operators

Unary operators

  • (unary minus)
  • (unary +) ~

! not

Binary arithmetic operators

& (binary & or formal block arg)

  • (binary minus) %
  • (binary *) ** / (binary /) ^ |
  • (binary +) << (left shift)

Match operators

=~ !~

Comparison operators

<

= <= <=> == != ===

Language-defined operators

Assignment

=

Complex assignment

&&= ||=

|= %= &= **= *= ^= -= += /= <<=

=

Logical operators

&& || ? (ternary ?:) and or

defined?

defined?

Range constructors

Also for flipflops

.. ...

Operator precedence

No Type Description Operators Associativity
1 Unary General ! ~ + Right
2 Binary Power ** Right
3 Unary Minus - Right
4 Binary Products * / % Left
5 Binary Additions + - Left
6 Binary Shifts << >> Left
7 Binary Bitwise and & Left
8 Binary Bitwise or ` ^`
9 Binary Directional comparisons > >= < <= Left (why?)
10 Binary General comparisons <=> == === != =~ !~ None
11 Binary Logical and, argument form && Left
12 Binary Logical or, argument form `
13 Binary Range constructors .. ... Left

%right '?' ':' %left modifier_rescue %right '=' tOP_ASGN %nonassoc keyword_defined %right keyword_not %left keyword_or keyword_and %nonassoc modifier_if modifier_unless modifier_while modifier_until

Clone this wiki locally