Class: DressUp::Outfit

Inherits:
Object
  • Object
show all
Defined in:
lib/dress_up/outfit.rb

Overview

Outfit represents a set of costumes in use by a given object.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#costumesObject (readonly)

Returns the value of attribute costumes.



5
6
7
# File 'lib/dress_up/outfit.rb', line 5

def costumes
  @costumes
end

#getupObject (readonly)

Returns the value of attribute getup.



5
6
7
# File 'lib/dress_up/outfit.rb', line 5

def getup
  @getup
end

#objectObject (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.

Returns:

  • (Boolean)


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