Many of Ruby’s operators, such as +
, *
, and even the array index operator []
, are implemented with methods that you can define in your own classes.
You define an operator by defining a method with
the same “name” as the operator. (The only exceptions are the unary plus and minus operators, which use method names +@
and -@
.)