可以覆盖/实现的 ruby​​ 运算符列表

发布于 2024-09-11 08:09:36 字数 43 浏览 6 评论 0原文

是否有可以覆盖的所有 ruby​​ 运算符的列表? (不是那些不能的!)

Is there a list anywhere of all ruby operators that can be overridden? (Not the ones that can't!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2024-09-18 08:09:37

这是Ruby 运算符表

属于方法和可重载的有:

[ ] [ ]=    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 书中的表相同 —— 没有理由相信这组中缀运算符会发生变化。

Here's a table of the Ruby operators.

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)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文