Redefining Float#/
appears to have no effect:
class Float
def /(other)
"magic!"
end
end
puts 10.0/2.0 # => 5.0
But when another infix operator Float#*
is redefined, Float#/
suddenly takes on the new definition:
class Float
def /(other)
"magic!"
end
def *(other)
"spooky"
end
end
puts 10.0/2.0 # => "magic!"
I would love to hear if anybody can explain the source of this behavior and if anybody else gets the same results.
To quickly confirm the bug, run this script.
This appears to be a bug in the implementation of Ruby. A bug report has been filed here.
In the mean time, you may either switch implementations or switch versions. 1.8.7 appears to be bug free.
EDIT
This bug was fixed with revision 44127
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With