是否有可以覆盖的所有 ruby 运算符的列表? (不是那些不能的!)
Here's Ruby 运算符表 http://phrogz.net/programmingruby/language.html#table_18.4.
方法和可重载的有:
[ ] [ ]= 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)
该表来自 2001 Pickaxe 书中,但这与 Ruby 1.9 Pickaxe 书中的表相同——没有理由相信这组中缀运算符会发生变化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)