Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list of ruby operators that can be overridden/implemented

Is there a list anywhere of all ruby operators that can be overridden? (Not the ones that can't!)

like image 786
aaaidan Avatar asked Jul 26 '10 02:07

aaaidan


People also ask

Which operators Cannot be overridden?

(::) Scope resolution operator cannot be overloaded in C language.

Does Ruby support operator overloading?

Ruby permits operator overloading, allowing one to define how an operator shall be used in a particular program. For example a '+' operator can be define in such a way to perform subtraction instead addition and vice versa.


1 Answers

Here's a table of the Ruby operators.

The ones that are methods and overloadable are:

[ ] [ ]=    Element reference, element set **  Exponentiation ! ~ + -     Not, complement, unary plus and minus (method names for the last two are +@ and -@) * / %   Multiply, divide, and modulo + -     Plus and minus >> <<   Right and left shift &   Bitwise `and' ^ |     Bitwise exclusive `or' and regular `or' <= < > >=   Comparison operators <=> == === != =~ !~     Equality and pattern match operators (!= and !~ may not be defined as methods) 

The table was from the 2001 Pickaxe book, but that's the same table as in the Ruby 1.9 Pickaxe book -- no reason to believe that this set of infix operators will ever change.

like image 122
Mark Rushakoff Avatar answered Sep 22 '22 17:09

Mark Rushakoff