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.11.20 lib/coderunner/merged_code_runner.rb
coderunner-0.11.19 lib/coderunner/merged_code_runner.rb
coderunner-0.11.18 lib/coderunner/merged_code_runner.rb
coderunner-0.11.17 lib/coderunner/merged_code_runner.rb
coderunner-0.11.16 lib/coderunner/merged_code_runner.rb
coderunner-0.11.15 lib/coderunner/merged_code_runner.rb
coderunner-0.11.14 lib/coderunner/merged_code_runner.rb
coderunner-0.11.13 lib/coderunner/merged_code_runner.rb
coderunner-0.11.12 lib/coderunner/merged_code_runner.rb
coderunner-0.11.11 lib/coderunner/merged_code_runner.rb
coderunner-0.11.10 lib/coderunner/merged_code_runner.rb
coderunner-0.11.9 lib/coderunner/merged_code_runner.rb
coderunner-0.11.8 lib/coderunner/merged_code_runner.rb
coderunner-0.11.7 lib/coderunner/merged_code_runner.rb
coderunner-0.11.6 lib/coderunner/merged_code_runner.rb
coderunner-0.11.5 lib/coderunner/merged_code_runner.rb
coderunner-0.11.4 lib/coderunner/merged_code_runner.rb
coderunner-0.11.3 lib/coderunner/merged_code_runner.rb
coderunner-0.11.2 lib/coderunner/merged_code_runner.rb
coderunner-0.11.1 lib/coderunner/merged_code_runner.rb