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…

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s