Class: MarcBot::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/marc_bot/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Registry

Returns a new instance of Registry.



7
8
9
10
# File 'lib/marc_bot/registry.rb', line 7

def initialize(name)
  @name = name
  @items = {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/marc_bot/registry.rb', line 5

def name
  @name
end

Instance Method Details

#clearObject



12
13
14
# File 'lib/marc_bot/registry.rb', line 12

def clear
  items.clear
end

#find(name) ⇒ Object Also known as: []



16
17
18
# File 'lib/marc_bot/registry.rb', line 16

def find(name)
  items[name] || raise(Error, "item :#{name} does not exist in the registry. Did you define it?")
end

#register(name, item) ⇒ Object



21
22
23
# File 'lib/marc_bot/registry.rb', line 21

def register(name, item)
  items[name] = item
end

#registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/marc_bot/registry.rb', line 25

def registered?(name)
  items.key?(name)
end