Created
July 12, 2011 16:45
-
-
Save stephenprater/1078389 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
class Factory | |
class << self | |
def new_thing name | |
klass = Class.new(self) do | |
attr_accessor :name | |
define_method :initialize do | |
@name = name | |
end | |
end | |
const_name = name.camelize.intern | |
old_klass = remove_const const_name if const_defined? const_name | |
old_klass = nil | |
self.const_set const_name, klass | |
klass | |
end | |
end | |
end | |
Factory.new_thing "bob" | |
Factory.subclasses | |
#[Factory::Bob] | |
Factory.new_thing "bob" | |
Factory.subclasses | |
#[Factory::Bob, Factory::Bob] | |
# Shouldn't there still only be one Factory::Bob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment