Class: TheArrayComparator::CachingStrategies::AnonymousCache
- Inherits:
-
Object
- Object
- TheArrayComparator::CachingStrategies::AnonymousCache
- Defined in:
- lib/the_array_comparator/caching_strategies/anonymous_cache.rb
Overview
anonymous cache
Instance Method Summary collapse
-
#add(obj) ⇒ Object
Add object to cache.
-
#clear ⇒ Object
Clear the cache (delete all objects).
-
#delete_object(num) ⇒ Object
Delete an object from cache by number.
-
#fetch_object(num) ⇒ Object
Request an object from cache by number.
-
#initialize ⇒ AnonymousCache
constructor
Create cache.
-
#new_objects? ⇒ TrueClass, FalseClass
Are there new objects.
-
#stored_objects ⇒ Array
Return all stored objects.
Constructor Details
#initialize ⇒ AnonymousCache
Create cache
11 12 13 14 |
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 11 def initialize @cache = [] @new_objects = false end |
Instance Method Details
#add(obj) ⇒ Object
Add object to cache
23 24 25 26 27 28 |
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 23 def add(obj) @cache << obj @new_objects = true obj end |
#clear ⇒ Object
Clear the cache (delete all objects)
40 41 42 |
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 40 def clear @cache = [] end |
#delete_object(num) ⇒ Object
Delete an object from cache by number
56 57 58 |
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 56 def delete_object(num) @cache.delete_at(num) end |
#fetch_object(num) ⇒ Object
Request an object from cache by number
64 65 66 |
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 64 def fetch_object(num) @cache[num] end |
#new_objects? ⇒ TrueClass, FalseClass
Are there new objects
48 49 50 |
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 48 def new_objects? @new_objects end |
#stored_objects ⇒ Array
Return all stored objects
34 35 36 37 |
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 34 def stored_objects @new_objects = false @cache end |