Last active
December 12, 2015 15:34
-
-
Save ippeiukai/6f8ac64f6e3fba43002e to your computer and use it in GitHub Desktop.
2 + 2 = 5 in Ruby. (http://en.wikipedia.org/wiki/Two_plus_two_make_five)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TwoPlusTwoIsFive | |
def self.included(base) | |
base.class_exec do | |
alias_method :plus_without_two_plus_two_is_five, :+ | |
private :plus_without_two_plus_two_is_five | |
alias_method :+, :plus_with_two_plus_two_is_five | |
public :+ | |
end | |
end | |
private | |
def plus_with_two_plus_two_is_five(other) | |
other += 1 if self == 2 && other == 2 | |
plus_without_two_plus_two_is_five(other) | |
end | |
end | |
Fixnum.send(:include, TwoPlusTwoIsFive) | |
Float.send(:include, TwoPlusTwoIsFive) |
In spirit of RubyKaigi 2015, confirmed on 2.3.0-preview1.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
confirmed to work with all MRI, JRuby and Rubinius.