Class: Threatinator::Registry
- Inherits:
-
Object
- Object
- Threatinator::Registry
- Includes:
- Exceptions
- Defined in:
- lib/threatinator/registry.rb
Overview
Just a simple class that holds stuff. Yup, a glorified hash.
Direct Known Subclasses
Instance Method Summary collapse
-
#clear ⇒ Object
Removes all objects from the registry.
-
#count ⇒ Integer
The number of objects in the registry.
-
#each {|object| ... } ⇒ Object
Enumerates through each object in our registry.
- #get(key) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#keys ⇒ Array<Object>
An array of keys.
- #register(key, object) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
8 9 10 |
# File 'lib/threatinator/registry.rb', line 8 def initialize() @data= Hash.new end |
Instance Method Details
#clear ⇒ Object
Removes all objects from the registry
48 49 50 |
# File 'lib/threatinator/registry.rb', line 48 def clear @data.clear end |
#count ⇒ Integer
Returns the number of objects in the registry.
35 36 37 |
# File 'lib/threatinator/registry.rb', line 35 def count @data.count end |
#each {|object| ... } ⇒ Object
Enumerates through each object in our registry
42 43 44 45 |
# File 'lib/threatinator/registry.rb', line 42 def each(&block) return enum_for(:each) unless block_given? @data.each_pair(&block) end |
#get(key) ⇒ Object
25 26 27 |
# File 'lib/threatinator/registry.rb', line 25 def get(key) @data[key] end |
#keys ⇒ Array<Object>
Returns an array of keys.
30 31 32 |
# File 'lib/threatinator/registry.rb', line 30 def keys @data.keys end |
#register(key, object) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/threatinator/registry.rb', line 16 def register(key, object) if @data.has_key?(key) raise AlreadyRegisteredError.new(key) end @data[key] = object end |