Class: Switches::Collection
- Inherits:
-
Object
- Object
- Switches::Collection
- Defined in:
- lib/switches/collection.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #include?(name) ⇒ Boolean
-
#initialize(klass, instance) ⇒ Collection
constructor
A new instance of Collection.
- #reload(name) ⇒ Object
Constructor Details
#initialize(klass, instance) ⇒ Collection
Returns a new instance of Collection.
3 4 5 6 7 8 9 10 11 |
# File 'lib/switches/collection.rb', line 3 def initialize(klass, instance) @collection = Hash.new do |collection, name| name = name.to_sym item = klass.new(name, instance) item.reload collection[name] = item end end |
Instance Method Details
#[](name) ⇒ Object
13 14 15 |
# File 'lib/switches/collection.rb', line 13 def [](name) @collection[name.to_sym] end |
#include?(name) ⇒ Boolean
27 28 29 |
# File 'lib/switches/collection.rb', line 27 def include?(name) @collection.keys.include?(name.to_sym) end |
#reload(name) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/switches/collection.rb', line 17 def reload(name) name = name.to_sym if include?(name) @collection[name].reload else @collection[name] end end |