代码之家  ›  专栏  ›  技术社区  ›  aaaidan

可以重写/实现的ruby操作符列表

  •  24
  • aaaidan  · 技术社区  · 14 年前

    是否有一个可以覆盖的所有ruby操作符的列表(不是那些不能的!)

    1 回复  |  直到 11 年前
        1
  •  35
  •   Mark Rushakoff    14 年前

    这里是 a table of the Ruby operators .

    可重载的方法有:

    [ ] [ ]=    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手册,但它与Ruby1.9 Pickaxe手册中的表是相同的——没有理由相信这组中缀运算符会改变。