Ruby methoswith operator-style syntactic sugar calling notat

1, +
Definition:
def +(x)

Calling:
obj.+(x)

Sugared notation:
obj + x


2, -
Definition:
def -(x)

Calling:
obj.-(x)

Sugared notation:
obj - x


3, *
Definition:
def *(x)

Calling:
obj.*(x)

Sugared notation:
obj * x


4, /
Definition:
def /(x)

Calling:
obj./(x)

Sugared notation:
obj / x


5, %
Definition:
def %(x)

Calling:
obj.%(x)

Sugared notation:
obj % x


6, []
Definition:
def [](x)

Calling:
obj.[](x)

Sugared notation:
obj[x]


7, []=
Definition:
def []=(x, y)

Calling:
obj.[]=(x, y)

Sugared notation:
obj[x] = y


8, <<
Definition:
def <<(x)

Calling:
obj.<<(x)

Sugared notation:
obj << x


9, ==
Definition:
def ==(x)

Calling:
obj.==(x)

Sugared notation:
obj == x


10, >
Definition:
def >(x)

Calling:
obj.>(x)

Sugared notation:
obj > x


11, <
Definition:
def <(x)

Calling:
obj.<(x)

Sugared notation:
obj < x


12, >=
Definition:
def >=(x)

Calling:
obj.>=(x)

Sugared notation:
obj >= x


13, <=
Definition:
def <=(x)

Calling:
obj.<=(x)

Sugared notation:
obj <= x


14, ===
Definition:
def ===(x)

Calling:
obj.===(x)

Sugared notation:
obj === x

你可能感兴趣的:(Ruby)