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

.. ...

Operator precedence

%nonassoc modifier_if modifier_unless modifier_while modifier_until %left keyword_or keyword_and %right keyword_not %nonassoc keyword_defined %right '=' tOP_ASGN %left modifier_rescue %right '?' ':' %nonassoc tDOT2 tDOT3 %left tOROP %left tANDOP %nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH %left '>' tGEQ '<' tLEQ %left '|' '^' %left '&' %left tLSHFT tRSHFT %left '+' '-' %left '*' '/' '%' %right tUMINUS_NUM tUMINUS %right tPOW %right '!' '~' tUPLUS

No Description Operators Associativity
1 Unary ! ~ + Right
2 Power **
3 Unary minus -

Clone this wiki locally