Backport #9238
closed
Monkey Patching Float class Infix Operators Produces Unexpected Result
Added by screenmutt (Dan Grahn) almost 11 years ago.
Updated almost 11 years ago.
Description
Hello!
Patching Float class infix operators seem to work only if 2 are present. See the code below.
class Float
def /(other)
"magic"
end
end
first_result = 10.0 / 2.0
class Float
def *(other)
"weird"
end
end
second_result = 10.0 / 2.0
if first_result == 5.0 && second_result == "magic"
puts "Bug confirmed"
else
puts "Bug not present"
end
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r44127.
Dan, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- insns.def: Fix optimization bug of Float#/ [Bug #9238]
Cute bug.
You were lucky to figure out that redefining * "fixed" it!
Would have loved to mention that in my rubyconf talk :-)
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Status changed from Closed to Open
- Assignee set to nagachika (Tomoyuki Chikanaga)
- Status changed from Open to Closed
This issue was solved with changeset r44326.
Dan, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 44127: [Backport #9238]
* insns.def: Fix optimization bug of Float#/ [Bug #9238]
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0