Issue #9238 has been updated by screenmutt (Dan Grahn).


I just saw this bug posted at https://bugs.ruby-lang.org/issues/9237. Please mark as duplicate.
----------------------------------------
Bug #9238: Monkey Patching Float class Infix Operators Produces Unexpected Result
https://bugs.ruby-lang.org/issues/9238#change-43583

Author: screenmutt (Dan Grahn)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


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


-- 
http://bugs.ruby-lang.org/