Last active
December 14, 2015 00:29
-
-
Save jjb/4999475 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Object | |
def self.typecheck(object) | |
unless self == object.class | |
raise ArgumentError, | |
"expected type: #{self}. given: #{object.class}." | |
end | |
end | |
end | |
class Foo; end | |
class Bar; end | |
def my_method(arg1, arg2) | |
Foo.typecheck arg1 | |
Bar.typecheck arg2 | |
puts "The method finished!" | |
end | |
puts "1..." | |
my_method(Foo.new, Bar.new) | |
puts "2..." | |
my_method("hi.", Bar.new) |
This file contains hidden or 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
1... | |
The method finished! | |
2... | |
driver.rb:4:in `typecheck': expected type: Foo. given: String. (ArgumentError) | |
from driver.rb:14:in `my_method' | |
from driver.rb:23:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment