Created
August 20, 2014 17:13
-
-
Save kristjan/540efd83a7637f087b64 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
module RequireImplementation | |
def require_implementation(method_name) | |
define_method method_name do | |
raise NotImplementedError, "#{self.class.name} must implement #{method_name}" | |
end | |
end | |
end | |
class TestClass | |
extend RequireImplementation | |
require_implementation :foo | |
end | |
class BrokenSubclass < TestClass | |
end | |
class WorkingSubclass < TestClass | |
def foo | |
puts "Fooey" | |
end | |
end | |
begin | |
BrokenSubclass.new.foo | |
rescue Exception => ex | |
puts ex.message | |
end | |
WorkingSubclass.new.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment