Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created March 27, 2012 22:49
Show Gist options
  • Save jballanc/2221205 to your computer and use it in GitHub Desktop.
Save jballanc/2221205 to your computer and use it in GitHub Desktop.
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