Skip to content

Instantly share code, notes, and snippets.

@kristjan
Created August 20, 2014 17:13
Show Gist options
  • Save kristjan/540efd83a7637f087b64 to your computer and use it in GitHub Desktop.
Save kristjan/540efd83a7637f087b64 to your computer and use it in GitHub Desktop.
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