Module: Evolvable::Gene::ClassMethods
- Defined in:
- lib/evolvable/gene.rb
Overview
Class methods added to classes that include Evolvable::Gene. These methods enable gene-level behaviors like combination during evolution.
Instance Method Summary collapse
-
#combine(gene_a, gene_b) ⇒ Evolvable::Gene
Combines two genes to produce a new gene during the combination phase.
-
#key ⇒ Symbol
Returns the unique key for this gene type.
-
#key=(val) ⇒ Object
Sets the unique key for this gene type.
Instance Method Details
#combine(gene_a, gene_b) ⇒ Evolvable::Gene
Combines two genes to produce a new gene during the combination phase. By default, randomly picks one of the two parent genes.
Override this method in your gene class to implement custom combination behavior.
141 142 143 |
# File 'lib/evolvable/gene.rb', line 141 def combine(gene_a, gene_b) [gene_a, gene_b].sample end |
#key ⇒ Symbol
Returns the unique key for this gene type.
127 128 129 |
# File 'lib/evolvable/gene.rb', line 127 def key @key end |
#key=(val) ⇒ Object
Sets the unique key for this gene type.
The key is typically set automatically when using the gene
macro.
118 119 120 |
# File 'lib/evolvable/gene.rb', line 118 def key=(val) @key = val end |