Skip to content

Instantly share code, notes, and snippets.

@dbrady
Forked from blowmage/edgecase.rb
Created July 27, 2011 07:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
@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