Project

General

Profile

Actions

Backport #9238

closed

Monkey Patching Float class Infix Operators Produces Unexpected Result

Added by screenmutt (Dan Grahn) over 10 years ago. Updated over 10 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

Related issues 1 (0 open1 closed)

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

Updated by screenmutt (Dan Grahn) over 10 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) over 10 years ago

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

Actions #3

Updated by marcandre (Marc-Andre Lafortune) over 10 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) over 10 years ago

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

Actions #5

Updated by marcandre (Marc-Andre Lafortune) over 10 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)
Actions #6

Updated by nagachika (Tomoyuki Chikanaga) over 10 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]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0