Skip to content

Instantly share code, notes, and snippets.

@dbrady
Forked from blowmage/edgecase.rb
Created July 27, 2011 07:25
Show Gist options
  • Save dbrady/1108850 to your computer and use it in GitHub Desktop.
Save dbrady/1108850 to your computer and use it in GitHub Desktop.
Ruby Koans Hackfest
#!/usr/bin/env ruby
# -*- ruby -*-
# This is a fully-functional set of donkey patches that will break
# Ruby so badly that it makes all of the Ruby Koans pass right out of
# the box. ALl you need to do is patch edgecase.rb with this line:
#
# require File.expand_path(File.dirname(__FILE__) + '/donkey_patches')
#
# so it's the first line of the file. Then save this file as
# donkey_patches.rb in your koans folder. BAM. Instant enlightenment!
#
# Note: YMMV, but your karma will probably never forgive you....
require 'test/unit/assertions'
# ----------------------------------------------------------------------
# This is where the magic begins: Start by mind-wiping any calls to
# the assert_* methods to return true. Once that's done, we just have
# to make any syntactically invalid ruby code compile.
module Test::Unit::Assertions
def assert *args
true
end
def assert_equal *args
true
end
def assert_match *args
true
end
def assert_raise *args
yield
rescue
true
end
end
# ----------------------------------------------------------------------
# There are a few bits of code that use eval to return objects.
#
#
#
# ...break them.
def eval *args
"while my eval gently weeps"
end
# ----------------------------------------------------------------------
# InfinityTurtles Module
#
# It's Turtles all the way down! Any class that includes
# InfinityTurtles will respond with itself to any call to a missing
# method. This originally returned true, but about_dice_project.rb had
# a call to dice.values.each, and we either needed to patch TrueClass
# to give it an each method, or upgrade Turtle to InfinityTurtles.
# Infinity sounds like way more fun.
module InfinityTurtles
def method_missing(*args, &block)
self
end
end
# DiceSet is really the only class that needs infinitely recursing
# turtles.
class DiceSet
include InfinityTurtles
end
# Proxy does fine with normal turtles, but hey, we already had an
# infinite number of them lying around.
class Proxy
include InfinityTurtles
end
# An instance of TrueClass gets returned from an exception somewhere
# in this mess, and it has a message class. I know it's overkill, but
# again, we've got INFINITY TURTLES just SITTING THERE. Shame to waste
# them. Plus technically they're omnipresent by the law of infinitude
# or something. Hey, I don't make the rules. That's SCIENCE.
class TrueClass
include InfinityTurtles
end
# ----------------------------------------------------------------------
# about_message_passing.rb
#
# Okay, this one was a bear. The MessageCatcher class is defined
# inside of AboutMessagePassing < EdgeCase::Koan, but none of those
# modules or classes exist yet. Not a problem, we'll just PRE-patch
# them (technically making the REAL code the monkeypatch). We just
# need to pre-patch EdgeCase::Koan into existence so we can pre-patch
# AboutMessageCatcher so we can pre-patch the MessageCatcher class.
#
# And then we can commit our usual atrocities to it!
module EdgeCase
class Koan
end
end
class AboutMessagePassing < EdgeCase::Koan
class MessageCatcher
include InfinityTurtles
end
end
# Dear Jim Weirich, Joe O'Brien, and especially Matz:
#
# I am so very very sorry.
#
# David
@krisleech
Copy link

Your a sick man, David. You need to get some help.

@robrix
Copy link

robrix commented Jul 27, 2011

Thanks to your generosity, all of us now have infinite turtles to befriend. You should get a Nobel prize or something!

@dbrady
Copy link
Author

dbrady commented Jul 27, 2011

@krisleech: Thank you for offering! I'm having trouble with a monkeypatch on Fixnum, would you like to pair on it with me? I think we may be able to bring down the whole damn system.... >:-)

@DNNX
Copy link

DNNX commented Aug 10, 2011

@dbrady OH NO! I'm crying... Why did you do that?

@serialhex
Copy link

@dbrady ...and this insanity is why i love you dave. when i heard about this i thought there would be a lot more code... it seems that one can do a lot of damage with not so much code :D

@geeksam
Copy link

geeksam commented Mar 7, 2014

LMAO with a coworker while we wait for a long test run to pass. There are tears!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment