Sha256: af9725e84566c05eefc3b079a9b4aaa536d168451065a6e8cead75e6b5409b89

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

#==============================================================================#
# $Id: composite.rb 99 2008-07-17 13:56:26Z yuyakato $
#==============================================================================#

class Kagemusha
  class Composite
    def initialize(*mocks)
      @mocks = []
      mocks.each { |mock| self << mock }
    end

    attr_reader :mocks

    def size
      return @mocks.size
    end

    def add(mock)
      raise(ArgumentError) unless mock.kind_of?(Kagemusha) || mock.kind_of?(Kagemusha::Composite)
      @mocks << mock
      return self
    end
    alias << add

    def concat(mock)
      return self.class.new(*self.mocks) << mock
    end
    alias + concat

    def swap(&block)
      src = (0...self.size).to_a.reverse.inject("return yield") { |memo, index|
        "@mocks[#{index}].swap { #{memo} }"
      }
      return eval(src, &block)
    end
  end
end

#==============================================================================#
#==============================================================================#

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kagemusha-0.0.7 lib/kagemusha/composite.rb