Created
March 27, 2012 22:49
-
-
Save jballanc/2221205 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
class Pass | |
def self.===(o) | |
false | |
end | |
end | |
module Case | |
def test_it(test) | |
case test | |
when (self.kind_of?(Class) ? self : Pass) | |
puts "Tested by my class" | |
when self.class | |
puts "Tested by an instance of my class" | |
else | |
puts "Tested by something else..." | |
end | |
end | |
end | |
class Tester | |
class<<self | |
include Case | |
end | |
include Case | |
end | |
t = Tester.new | |
Tester.test_it("A string") | |
Tester.test_it(t) | |
Tester.new.test_it(t) | |
Tester.new.test_it(Pass.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment