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.24 lib/coderunner/merged_code_runner.rb
coderunner-0.14.23 lib/coderunner/merged_code_runner.rb
coderunner-0.14.22 lib/coderunner/merged_code_runner.rb
coderunner-0.14.21 lib/coderunner/merged_code_runner.rb
coderunner-0.14.20 lib/coderunner/merged_code_runner.rb
coderunner-0.14.19 lib/coderunner/merged_code_runner.rb
coderunner-0.14.18 lib/coderunner/merged_code_runner.rb
coderunner-0.14.17 lib/coderunner/merged_code_runner.rb
coderunner-0.14.16 lib/coderunner/merged_code_runner.rb
coderunner-0.14.15 lib/coderunner/merged_code_runner.rb
coderunner-0.14.14 lib/coderunner/merged_code_runner.rb
coderunner-0.14.13 lib/coderunner/merged_code_runner.rb
coderunner-0.14.12 lib/coderunner/merged_code_runner.rb
coderunner-0.14.11 lib/coderunner/merged_code_runner.rb
coderunner-0.14.10 lib/coderunner/merged_code_runner.rb
coderunner-0.14.9 lib/coderunner/merged_code_runner.rb
coderunner-0.14.8 lib/coderunner/merged_code_runner.rb
coderunner-0.14.7 lib/coderunner/merged_code_runner.rb
coderunner-0.14.6 lib/coderunner/merged_code_runner.rb
coderunner-0.14.5 lib/coderunner/merged_code_runner.rb