重新定义Float#/似乎没有任何效果:
class Float
def /(other)
"magic!"
end
end
puts 10.0/2.0 # => 5.0但是,当另一个infix操作符Float#*被重新定义时,Float#/突然采用了新的定义:
class Float
def /(other)
"magic!"
end
def *(other)
"spooky"
end
end
puts 10.0/2.0 # => "magic!"我想知道是否有人能解释这种行为的来源,如果其他人得到同样的结果。
要快速确认错误,请运行这个剧本。
https://stackoverflow.com/questions/20501203
复制相似问题