Class: EvoSynth::MetaOperators::ConditionalCombinedOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/evosynth/operators/meta_operators/conditional_combined_operator.rb

Overview

TODO: document me, could be used to swap mutations after N generations

Instance Method Summary collapse

Constructor Details

#initializeConditionalCombinedOperator

Returns a new instance of ConditionalCombinedOperator.



32
33
34
# File 'lib/evosynth/operators/meta_operators/conditional_combined_operator.rb', line 32

def initialize
	@operators = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/evosynth/operators/meta_operators/conditional_combined_operator.rb', line 44

def method_missing(method_name, *args)
	raise "no operator to call" if @operators.empty?

	result = args
	@operators.each do |operator|
		result = operator[0].send(method_name, *result) if operator[1].call
	end

	result
end

Instance Method Details

#add(operator, &condition) ⇒ Object

condition has to return boolean



39
40
41
42
# File 'lib/evosynth/operators/meta_operators/conditional_combined_operator.rb', line 39

def add(operator, &condition)
	@operators << [operator, condition]
	self
end

#to_sObject



56
57
58
59
60
# File 'lib/evosynth/operators/meta_operators/conditional_combined_operator.rb', line 56

def to_s
	operators_to_s = []
	@operators.each { |op| operators_to_s << "#{op[0].to_s} (probability: #{op[1]})" }
	"conditional combinded operator <operators: #{operators_to_s.join(', ')}>"
end