-
-
Save guilherme/889866 to your computer and use it in GitHub Desktop.
A class that make an attribute unique.
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 A | |
attr_accessor :name | |
@@a_classes = [] | |
private_class_method :new | |
def A.find_or_create(name) | |
@@a_classes.each do |klass| | |
if klass.name == name | |
return klass | |
end | |
end | |
new_klass = new name | |
@@a_classes.push(new_klass) | |
new_klass | |
end | |
def initialize(name) | |
self.name = name | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment