Class: CollectionManager
- Inherits:
-
Object
- Object
- CollectionManager
- Defined in:
- lib/collection_manager.rb
Overview
Collection Manager Class to manage collections
Instance Method Summary collapse
-
#add(collection) ⇒ Object
Adds a new collection to the Hash object.
-
#all ⇒ Object
Returns all the collections.
-
#delete(id) ⇒ Object
Deletes a collection from the Hash object.
-
#find(id) ⇒ Object
Returns a collection form the Hash id with key as id.
-
#initialize ⇒ CollectionManager
constructor
A new instance of CollectionManager.
Constructor Details
#initialize ⇒ CollectionManager
Returns a new instance of CollectionManager.
8 9 10 11 |
# File 'lib/collection_manager.rb', line 8 def initialize @current_id = 0; @collections = Hash.new end |
Instance Method Details
#add(collection) ⇒ Object
Adds a new collection to the Hash object
Example:
>> cm = CollectionManager.new
>> cm.add(Stack.new)
Arguments:
a collection object, eg. Stack or Queue
23 24 25 26 |
# File 'lib/collection_manager.rb', line 23 def add(collection) @current_id += 1 @collections[@current_id] = collection end |
#all ⇒ Object
Returns all the collections
56 57 58 |
# File 'lib/collection_manager.rb', line 56 def all @collections end |
#delete(id) ⇒ Object
Deletes a collection from the Hash object
Example:
>> cm.delete(1)
Arguments:
id of the collection
37 38 39 |
# File 'lib/collection_manager.rb', line 37 def delete(id) @collections.delete(id) end |
#find(id) ⇒ Object
Returns a collection form the Hash id with key as id
Example:
>> cm.find(1)
=> value at key 1 in the Hash object
Arguments:
id of the collection
50 51 52 |
# File 'lib/collection_manager.rb', line 50 def find(id) @collections[id] end |