Created
June 12, 2015 11:48
-
-
Save badboy/974cf3c41d1f83a68c16 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
class Fixnum | |
alias_method :old_add, :+ | |
def +(other) | |
if other.kind_of?(String) | |
self.old_add(other.to_i).to_s | |
elsif other == 2 && self == 2 | |
:DONE | |
else | |
self.old_add(other) | |
end | |
end | |
alias_method :old_div, :/ | |
def /(other) | |
if other == 0 | |
Float::NAN | |
else | |
self.old_div(other) | |
end | |
end | |
def +@ | |
p :my_plus | |
if self < 10 | |
self+10 | |
else | |
self | |
end | |
end | |
end | |
class String | |
alias_method :old_add, :+ | |
def +(other) | |
if other.kind_of?(Array) && other.empty? | |
"[#{self}]" | |
else | |
self.old_add(other) | |
end | |
end | |
end | |
module Kernel | |
def range(*args) | |
if args.size == 2 | |
f = args.shift.to_i | |
l = args.shift.to_i | |
a = (f..l).to_a | |
1.upto(l/2 - 1).each do |i| | |
a[i] = l-1 | |
end | |
a | |
elsif args.size == 1 && args[0] == " " | |
['"', "!", " ", "!", '"'] | |
else | |
nil | |
end | |
end | |
end | |
p 2+"2" | |
p "2"+[] | |
p( 2/0 ) | |
p( + 2 ) | |
p( 2+2 ) | |
p range(" ") | |
p range(1,5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment