Class: Yuzu::Registrar::Register

Inherits:
Object
  • Object
show all
Defined in:
lib/yuzu/core/registrar.rb

Overview

Class Register includes routines for storing singletons of objects with a common base class that can be executed as a set.

Constant Summary collapse

@@registered =

Subclasses should redefine ‘registry` with a unique identifier equal to the name of the class variable that will contain the singletons.

{}

Class Method Summary collapse

Class Method Details

.register(name_to_class = {}) ⇒ Object

Subclasses of the Register should call this method after their definitions to register them into the registry.



19
20
21
22
23
24
25
26
27
28
# File 'lib/yuzu/core/registrar.rb', line 19

def self.register(name_to_class={})
  class_var = "@@#{self.registry}".to_sym
  register = class_variable_get(class_var)
  if register.nil?
    class_variable_set(class_var, {})
    register = {}
  end
  name_to_instance = Hash[name_to_class.collect {|name, klass| [name, klass.new]}]
  class_variable_set(class_var, register.merge(name_to_instance))
end

.registeredObject



13
14
15
# File 'lib/yuzu/core/registrar.rb', line 13

def self.registered
  @@registered
end

.registryObject



10
11
12
# File 'lib/yuzu/core/registrar.rb', line 10

def self.registry
  :registered
end