Project

General

Profile

Actions

Bug #9237

closed

Monkey Patching Infix Float Operator's Produces Unexpected Results

Added by ChrisTimperley (Chris Timperley) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p353 (2013-11-22) [x64-mingw32]
[ruby-core:59026]

Description

=begin
Trying to redefine the infix division operator for the Float initially appears to have no effect.

class Float
  def /(other)
    "magic!"
  end
 end
 puts 10.0/2.0
 # -> 5.0

But when another infix operator is added the infix division operator suddenly takes on the new definition!

class Float
  def /(other)
    "magic!"
  end
  def *(other)
    "spooky"
  end
end
puts 10.0/2.0
# -> "magic!"

These results were returned when these programs were run in isolation.

((Ruby:)) ruby 2.0.0p353 (2013-11-22) [x64-mingw32]

((OS:)) Windows 7 Home Premium SP1 (x64)
=end


Related issues 1 (0 open1 closed)

Has duplicate Backport200 - Backport #9238: Monkey Patching Float class Infix Operators Produces Unexpected ResultClosednagachika (Tomoyuki Chikanaga)12/11/2013Actions

Updated by marcandre (Marc-Andre Lafortune) over 8 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF