Sha256: 54fde463b64eb6afef8f8120c9394e9855ccbc6e7b44653d2f5d4c69b37b8117

Contents?: true

Size: 819 Bytes

Versions: 101

Compression:

Stored size: 819 Bytes

Contents

class CodeRunner
	
	def merge(*others)
		Merged.new(*others.unshift(self))
	end
	
	def merge_method(meth, *args)
		send(meth, *args)
	end

	class Merged < CodeRunner
		def each
			@runners.each{|r| yield(r)}
		end
		include Enumerable
		def initialize(*runners)
			@runners = []
			r = runners[0]
			r.instance_variables.each do |v| 
				instance_variable_set(v, r.instance_variable_get(v))
			end
			@run_list = {}
			runners.each{|runner| add_runner(runner)}
		end
		def add_runner(runner)
			@runners.push runner
			runner.run_list.each do |id, run|
				#raise "Duplicate ids: #{id}" if @run_list[id]
				@run_list[id] = run
			end
			@ids = @run_list.keys
		end
		def merge_method(meth, *args, &block)
			results = @runners.map{|r| r.send(meth, *args)}
			return results.inject{|o,n| yield(o,n)}
		end

		
	end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
coderunner-0.14.4 lib/coderunner/merged_code_runner.rb
coderunner-0.14.3 lib/coderunner/merged_code_runner.rb
coderunner-0.14.2 lib/coderunner/merged_code_runner.rb
coderunner-0.14.1 lib/coderunner/merged_code_runner.rb
coderunner-0.14.0 lib/coderunner/merged_code_runner.rb
coderunner-0.13.32 lib/coderunner/merged_code_runner.rb
coderunner-0.13.31 lib/coderunner/merged_code_runner.rb
coderunner-0.13.30 lib/coderunner/merged_code_runner.rb
coderunner-0.13.29 lib/coderunner/merged_code_runner.rb
coderunner-0.13.28 lib/coderunner/merged_code_runner.rb
coderunner-0.13.27 lib/coderunner/merged_code_runner.rb
coderunner-0.13.26 lib/coderunner/merged_code_runner.rb
coderunner-0.13.25 lib/coderunner/merged_code_runner.rb
coderunner-0.13.24 lib/coderunner/merged_code_runner.rb
coderunner-0.13.23 lib/coderunner/merged_code_runner.rb
coderunner-0.13.22 lib/coderunner/merged_code_runner.rb
coderunner-0.13.21 lib/coderunner/merged_code_runner.rb
coderunner-0.13.20 lib/coderunner/merged_code_runner.rb
coderunner-0.13.19 lib/coderunner/merged_code_runner.rb
coderunner-0.13.18 lib/coderunner/merged_code_runner.rb