Class: MarcBot::Registry
- Inherits:
-
Object
- Object
- MarcBot::Registry
- Includes:
- Enumerable
- Defined in:
- lib/marc_bot/registry.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clear ⇒ Object
- #find(name) ⇒ Object (also: #[])
-
#initialize(name) ⇒ Registry
constructor
A new instance of Registry.
- #register(name, item) ⇒ Object
- #registered?(name) ⇒ Boolean
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
#name ⇒ Object (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
#clear ⇒ Object
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
25 26 27 |
# File 'lib/marc_bot/registry.rb', line 25 def registered?(name) items.key?(name) end |