kar*_*dog 7 ruby rubinius yarv super
这引发了我在1.9.2 Ruby中的SystemStackError(但在Rubinius中工作):
class Fixnum
def +(other)
self + other * 2
end
end
Run Code Online (Sandbox Code Playgroud)
但没有super了+(基于其他错误).
我如何访问原始+功能?
Fra*_*ser 14
使用alias_method.别名Fixnum的+别的东西,然后参考它在新的+:
class Fixnum
alias_method :old_add, :+
def +(other)
self.old_add(other) * 2
end
end
Run Code Online (Sandbox Code Playgroud)