Class: DressUp::Costume

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

Overview

Costume represents a named set of method overrides.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#overridesObject (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