Class: DressUp::Outfit
- Inherits:
-
Object
- Object
- DressUp::Outfit
- Defined in:
- lib/dress_up/outfit.rb
Overview
Outfit represents a set of costumes in use by a given object.
Instance Attribute Summary collapse
-
#costumes ⇒ Object
readonly
Returns the value of attribute costumes.
-
#getup ⇒ Object
readonly
Returns the value of attribute getup.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#apply(*other_costumes) ⇒ Object
Apply the given costumes to this outfit’s object.
-
#empty? ⇒ Boolean
Determine if this outfit has no costumes.
-
#initialize(object) ⇒ Outfit
constructor
Create a new outfit with the given object.
-
#remove(*other_costumes) ⇒ Object
Remove the given costumes from this outfit’s object.
Constructor Details
#initialize(object) ⇒ Outfit
Create a new outfit with the given object. Method overrides provided by costumes associated with this outfit will be applied to this object.
10 11 12 13 14 |
# File 'lib/dress_up/outfit.rb', line 10 def initialize(object) @costumes = {} @getup = {} @object = object end |
Instance Attribute Details
#costumes ⇒ Object (readonly)
Returns the value of attribute costumes.
5 6 7 |
# File 'lib/dress_up/outfit.rb', line 5 def costumes @costumes end |
#getup ⇒ Object (readonly)
Returns the value of attribute getup.
5 6 7 |
# File 'lib/dress_up/outfit.rb', line 5 def getup @getup end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/dress_up/outfit.rb', line 5 def object @object end |
Instance Method Details
#apply(*other_costumes) ⇒ Object
Apply the given costumes to this outfit’s object. Costume overrides are applied in the order that costumes are put on.
18 19 20 21 22 23 24 |
# File 'lib/dress_up/outfit.rb', line 18 def apply(*other_costumes) change_getup do other_costumes.each do |costume| @costumes[costume.name] = costume.overrides end end end |
#empty? ⇒ Boolean
Determine if this outfit has no costumes.
36 37 38 |
# File 'lib/dress_up/outfit.rb', line 36 def empty? @costumes.empty? end |
#remove(*other_costumes) ⇒ Object
Remove the given costumes from this outfit’s object.
27 28 29 30 31 32 33 |
# File 'lib/dress_up/outfit.rb', line 27 def remove(*other_costumes) change_getup do other_costumes.each do |costume| @costumes.delete(costume.name) end end end |