Project

General

Profile

This project is closed and read-only.

Actions

Backport #9238

closed

Monkey Patching Float class Infix Operators Produces Unexpected Result

Backport #9238: Monkey Patching Float class Infix Operators Produces Unexpected Result

Added by screenmutt (Dan Grahn) almost 13 years ago. Updated over 12 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 - Bug #9237: Monkey Patching Infix Float Operator's Produces Unexpected ResultsClosedActions
Actions

Also available in: PDF Atom