Class: OrangeZest::Group
- Defined in:
- lib/orange_zest/group.rb
Overview
Wraps a collection of ‘Component`s into a single `Component`.
The associated instance within this class, ‘Main`, is a special group available everywhere which components can be added to easily.
Constant Summary collapse
- Main =
new
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
(also: #enabled?)
Whether to call ‘#update` or `#draw` on the items in this group.
-
#items ⇒ <Component>
The items within this group.
Attributes inherited from Component
Instance Method Summary collapse
-
#add(component) ⇒ Object
(also: #<<)
Adds a component to this group.
- #draw ⇒ Object
-
#initialize ⇒ Group
constructor
A new instance of Group.
-
#remove(component) ⇒ Object
(also: #delete)
Removes a component from this group.
- #update ⇒ Object
Methods inherited from Component
Constructor Details
#initialize ⇒ Group
Returns a new instance of Group.
13 14 15 16 |
# File 'lib/orange_zest/group.rb', line 13 def initialize @items = [] @enabled = true end |
Instance Attribute Details
#enabled ⇒ Boolean Also known as: enabled?
Whether to call ‘#update` or `#draw` on the items in this group.
20 21 22 |
# File 'lib/orange_zest/group.rb', line 20 def enabled @enabled end |
#items ⇒ <Component>
The items within this group.
11 12 13 |
# File 'lib/orange_zest/group.rb', line 11 def items @items end |
Instance Method Details
#add(component) ⇒ Object Also known as: <<
Adds a component to this group.
25 26 27 |
# File 'lib/orange_zest/group.rb', line 25 def add(component) @items << component end |
#draw ⇒ Object
42 43 44 45 |
# File 'lib/orange_zest/group.rb', line 42 def draw return unless enabled? items.each(&:draw) end |
#remove(component) ⇒ Object Also known as: delete
Removes a component from this group.
32 33 34 |
# File 'lib/orange_zest/group.rb', line 32 def remove(component) @items.delete(component) end |
#update ⇒ Object
37 38 39 40 |
# File 'lib/orange_zest/group.rb', line 37 def update return unless enabled? items.each(&:update) end |