Module: DressUp::Interface::InstanceMethods
- Defined in:
- lib/dress_up/interface.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
When included, define the outfit reader.
Instance Method Summary collapse
-
#dress_down ⇒ Object
Remove all the costumes defined for this object’s class.
-
#dress_up ⇒ Object
Apply all the costumes defined for this object’s class.
-
#put_on(costume_name) ⇒ Object
Apply the costume with the given name to this object and set up and outfit if necessary.
-
#take_off(costume_name) ⇒ Object
Remove the costume with the given name from this object and clear an existing outfit if necessary.
Class Method Details
.included(base) ⇒ Object
When included, define the outfit reader
36 37 38 39 40 |
# File 'lib/dress_up/interface.rb', line 36 def self.included(base) base.class_eval do attr_reader :outfit end end |
Instance Method Details
#dress_down ⇒ Object
Remove all the costumes defined for this object’s class. Clear an existing outfit if necessary.
78 79 80 81 |
# File 'lib/dress_up/interface.rb', line 78 def dress_down @outfit && @outfit.remove(*self.class.closet.values) @outfit = nil if @outfit && @outfit.empty? end |
#dress_up ⇒ Object
Apply all the costumes defined for this object’s class. Set up an oufit if necessary.
58 59 60 61 |
# File 'lib/dress_up/interface.rb', line 58 def dress_up @outfit ||= DressUp::Outfit.new(self) @outfit.apply(*self.class.closet.values) end |
#put_on(costume_name) ⇒ Object
Apply the costume with the given name to this object and set up and outfit if necessary. If the costume does not exist, an error is raised.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dress_up/interface.rb', line 45 def put_on(costume_name) costume = self.class.closet[costume_name] if costume @outfit ||= DressUp::Outfit.new(self) @outfit.apply(costume) costume else raise DressUp::Errors::UndefinedCostumeError, costume_name end end |
#take_off(costume_name) ⇒ Object
Remove the costume with the given name from this object and clear an existing outfit if necessary. If the costume does not exist, an error is raised.
66 67 68 69 70 71 72 73 74 |
# File 'lib/dress_up/interface.rb', line 66 def take_off(costume_name) costume = self.class.closet[costume_name] if costume @outfit && @outfit.remove(costume) @outfit = nil if @outfit && @outfit.empty? else raise DressUp::Errors::UndefinedCostumeError, costume_name end end |