On 12/2/22, iloveruby <iloveruby(a)protonmail.com> wrote:
I have learned that there are some special method
names, +@, -@, etc. which
are invoked by writing them before the object...mmmm interesting.
But seems it only works with +@ and -@... where could I find more
information about it? Can I create other XXX@ methods?
https://docs.ruby-lang.org/en/master/syntax/methods_rdoc.html#label-Method+…
To define unary methods minus and plus, follow the operator with an @
as in +@:
The @ is needed to differentiate unary minus and plus operators from
binary minus and plus operators.
You can also follow tilde and not (!) unary methods with @, but it is
not required as there are no binary tilde and not operators.
Unary methods accept zero arguments.
These are method names for the various Ruby operators. Each of these
operators accepts only one argument:
+ - * ** / % & ^ >> << == != === =~ !~ <=> < <= > >=