Sha256: 91f70da343adba43a6060a1694d5cf645b4e884ff5915ffda419cacbccd831b1
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
# coding: utf-8 #==============================================================================# # $Id: composite.rb 120 2009-02-09 08:22:25Z 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.8 | lib/kagemusha/composite.rb |