可以被覆盖/实现的Ruby操作符列表 [英] list of ruby operators that can be overridden/implemented
本文介绍了可以被覆盖/实现的Ruby操作符列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在所有可以替换的红宝石运算符的任何地方都有列表吗? (不是那些不能的!)
Is there a list anywhere of all ruby operators that can be overridden? (Not the ones that can't!)
推荐答案
以下是表格Ruby运算符.
属于方法且可重载的是:
The ones that are methods and overloadable are:
[ ] [ ]= 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的书籍相同.没有理由相信这组中缀运算符会发生变化.
The table was from the 2001 Pickaxe book, but that's the same table as in the Ruby 1.9 Pickaxe book -- no reason to believe that this set of infix operators will ever change.
这篇关于可以被覆盖/实现的Ruby操作符列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文