Project

General

Profile

Backport #9238

Monkey Patching Float class Infix Operators Produces Unexpected Result

Added by screenmutt (Dan Grahn) about 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:59027]

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

Related issues

Is duplicate of Ruby master - Bug #9237: Monkey Patching Infix Float Operator's Produces Unexpected ResultsClosed12/11/2013Actions

Updated by screenmutt (Dan Grahn) about 6 years ago

I just saw this bug posted at https://bugs.ruby-lang.org/issues/9237. Please mark as duplicate.

Updated by screenmutt (Dan Grahn) about 6 years ago

I just saw this bug posted at https://bugs.ruby-lang.org/issues/9237. Please mark as duplicate.

#3

Updated by marcandre (Marc-Andre Lafortune) about 6 years ago

  • 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]

Updated by marcandre (Marc-Andre Lafortune) about 6 years ago

Cute bug.
You were lucky to figure out that redefining * "fixed" it!
Would have loved to mention that in my rubyconf talk :-)

#5

Updated by marcandre (Marc-Andre Lafortune) about 6 years ago

  • 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)
#6

Updated by nagachika (Tomoyuki Chikanaga) about 6 years ago

  • 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