Fonte: Programming Ruby – The Pragmatic Programmers’ Guide
Operadores em Ruby (da maior para a menor prioridade)
|
Método |
Operador |
Descrição (em inglês) |
|
Sim |
[ ] [ ]= |
Element reference, element set |
|
Sim |
** |
Exponentiation (raise to the power) |
|
Sim |
! ~ + - |
Not, complement, unary plus and minus (method names for the last two are +@ and -@) |
|
Sim |
* / % |
Multiply, divide, and modulo |
|
Sim |
+ - |
Addition and subtraction |
|
Sim |
>> << |
Right and left bitwise shift |
|
Sim |
& |
Bitwise `AND’ |
|
Sim |
^ | |
Bitwise exclusive `OR’ and regular `OR’ |
|
Sim |
<= < > >= |
Comparison operators |
|
Sim |
<=> == === != =~ !~ |
Equality and pattern match operators (!= and !~ may not be defined as methods) |
|
Não |
&& |
Logical `AND’ |
|
Não |
|| |
Logical `AND’ |
|
Não |
.. … |
Range (inclusive and exclusive) |
|
Não |
? : |
Ternary if-then-else |
|
Não |
= %= { /= -= += |= &= >>= <<= *= &&= ||= **= |
Assignment |
|
Não |
defined? |
Check if specified symbol defined |
|
Não |
not |
Logical negation |
|
Não |
or and |
Logical composition |
|
Não |
if unless while until |
Expression modifiers |
|
Não |
begin/end |
Block expression |
Operadores com um Sim na coluna “Método” são realmente métodos e por isso podem ser sobrecarregados.

Comentários