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

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.

Parameters:

Returns:



141
142
143
# File 'lib/evolvable/gene.rb', line 141

def combine(gene_a, gene_b)
  [gene_a, gene_b].sample
end

#keySymbol

Returns the unique key for this gene type.

Returns:

  • (Symbol)

    The key that identifies 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.

Parameters:

  • val (Symbol)

    The key to identify this gene type



118
119
120
# File 'lib/evolvable/gene.rb', line 118

def key=(val)
  @key = val
end