Class: DressUp::Costume
- Inherits:
-
Object
- Object
- DressUp::Costume
- Defined in:
- lib/dress_up/costume.rb
Overview
Costume represents a named set of method overrides.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#overrides ⇒ Object
readonly
Returns the value of attribute overrides.
Instance Method Summary collapse
-
#[](override) ⇒ Object
Retreive an override by its identifier.
-
#initialize(name, overrides = {}) ⇒ Costume
constructor
Create a new costume with the given name and overrides.
Constructor Details
#initialize(name, overrides = {}) ⇒ Costume
Create a new costume with the given name and overrides. Overrides are converted into lambdas if necessary.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dress_up/costume.rb', line 9 def initialize(name, overrides={}) @name = name @overrides = overrides.inject({}) do |hash, (method_name, value)| unless value.respond_to? :call hash[method_name] = lambda { value } else hash[method_name] = value end hash end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dress_up/costume.rb', line 5 def name @name end |
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
5 6 7 |
# File 'lib/dress_up/costume.rb', line 5 def overrides @overrides end |
Instance Method Details
#[](override) ⇒ Object
Retreive an override by its identifier
22 23 24 |
# File 'lib/dress_up/costume.rb', line 22 def [](override) @overrides[override] end |