Module: RoadForest::Utility::ClassRegistry::Registrar
- Defined in:
- lib/roadforest/utility/class-registry.rb
Overview
Extend a module with this in order to make it the registrar for a particular purpose. The top of a class heirarchy will make “register” immediately available to subclasses. Otherwise, classes can say Module::registry.add(name, self)
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.extended(mod) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/roadforest/utility/class-registry.rb', line 24 def self.extended(mod) ( class << mod; self; end ).instance_exec(mod) do |mod| define_method :registrar do mod end end end |
Instance Method Details
#get(name) ⇒ Object Also known as: []
19 20 21 |
# File 'lib/roadforest/utility/class-registry.rb', line 19 def get(name) registrar.registry.get(name) end |
#register(name) ⇒ Object
15 16 17 |
# File 'lib/roadforest/utility/class-registry.rb', line 15 def register(name) registrar.registry.add(name, self) end |
#registry ⇒ Object
11 12 13 |
# File 'lib/roadforest/utility/class-registry.rb', line 11 def registry @registry ||= ClassRegistry.new(self) end |