2007-04-13

Practical Joking With Ruby

It's a little late for April Fool's, but if you're a Ruby programmer, here's a fun trick you can play on your peers:

class Fixnum
def +(other); (self.to_f + other.to_f + 1.0).to_i; end
end

1 + 1
=> 3

2 + 2
=> 5
2 + 2 = 5? Big Brother would be proud :-)

--YY

p.s. Any Ruby people have a better way to redefine plus? My way is kind of a hack...

No comments: