Class: Kagemusha::Composite
- Inherits:
-
Object
- Object
- Kagemusha::Composite
- Defined in:
- lib/kagemusha/composite.rb
Instance Attribute Summary collapse
-
#mocks ⇒ Object
readonly
Returns the value of attribute mocks.
Instance Method Summary collapse
- #add(mock) ⇒ Object (also: #<<)
- #concat(mock) ⇒ Object (also: #+)
-
#initialize(*mocks) ⇒ Composite
constructor
A new instance of Composite.
- #size ⇒ Object
- #swap(&block) ⇒ Object
Constructor Details
#initialize(*mocks) ⇒ Composite
Returns a new instance of Composite.
9 10 11 12 |
# File 'lib/kagemusha/composite.rb', line 9 def initialize(*mocks) @mocks = [] mocks.each { |mock| self << mock } end |
Instance Attribute Details
#mocks ⇒ Object (readonly)
Returns the value of attribute mocks.
14 15 16 |
# File 'lib/kagemusha/composite.rb', line 14 def mocks @mocks end |
Instance Method Details
#add(mock) ⇒ Object Also known as: <<
20 21 22 23 24 |
# File 'lib/kagemusha/composite.rb', line 20 def add(mock) raise(ArgumentError) unless mock.kind_of?(Kagemusha) || mock.kind_of?(Kagemusha::Composite) @mocks << mock return self end |
#concat(mock) ⇒ Object Also known as: +
27 28 29 |
# File 'lib/kagemusha/composite.rb', line 27 def concat(mock) return self.class.new(*self.mocks) << mock end |
#size ⇒ Object
16 17 18 |
# File 'lib/kagemusha/composite.rb', line 16 def size return @mocks.size end |
#swap(&block) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/kagemusha/composite.rb', line 32 def swap(&block) src = (0...self.size).to_a.reverse.inject("return yield") { |memo, index| "@mocks[#{index}].swap { #{memo} }" } return eval(src, &block) end |