Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
572 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...