In Ruby, like in many other OO programming languages, operators are overloadable. However, only certain character operators can be overloaded.
This list may be incomplete but, here are some of the operators that cannot be overloaded:
!, not, &&, and, ||, or
"The && and || operators are not overloadable, mainly because they provide "short circuit" evaluation that cannot be reproduced with pure method calls."
-- Jim Weirich
Methods are overloadable, those are part of the language syntax.
Yep. Operators are not overloadable. Only methods.
Some operators are not really. They're sugar for methods. So 5 + 5
is really 5.+(5)
, and foo[bar] = baz
is really foo.[]=(bar, baz)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With