Created
April 20, 2012 23:47
-
-
Save chriswailes/2432710 to your computer and use it in GitHub Desktop.
Abstract Class implementation for Ruby
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 AbstractClass | |
def self.included(klass) | |
klass.instance_exec do | |
@abstract_class = klass | |
def self.new(*args) | |
if self == @abstract_class | |
raise "Instantiating abstract class #{self} is not allowed." | |
else | |
super | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment