Class: Evolvable::RigidCountGene

Inherits:
Object
  • Object
show all
Includes:
Gene
Defined in:
lib/evolvable/rigid_count_gene.rb

Overview

This class manages fixed gene counts in evolvable instances. Unlike the CountGene, the RigidCountGene maintains a constant number of genes that doesn't change during evolution. This is used when a gene is defined with a fixed integer for count: (e.g., count: 5).

Examples:

Define a chord with exactly 4 notes

class Chord
  include Evolvable

  gene :notes, type: NoteGene, count: 4

  # The number of notes will always be 4, never changing during evolution
  def play
    puts "Playing chord with #{notes.count} notes"
  end
end

Instance Attribute Summary collapse

Attributes included from Gene

#evolvable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gene

included, #key

Constructor Details

#initialize(count) ⇒ RigidCountGene

Initializes a new RigidCountGene with a fixed count.

Parameters:

  • count (Integer)

    The fixed number of genes to create



42
43
44
# File 'lib/evolvable/rigid_count_gene.rb', line 42

def initialize(count)
  @count = count
end

Instance Attribute Details

#countInteger (readonly)

The fixed number of genes to create.

Returns:

  • (Integer)

    The gene count



51
52
53
# File 'lib/evolvable/rigid_count_gene.rb', line 51

def count
  @count
end

Class Method Details

.combine(gene_a, _gene_b) ⇒ RigidCountGene

Combines two rigid count genes by always returning the first one. This ensures the count remains constant during evolution.

Parameters:

Returns:



33
34
35
# File 'lib/evolvable/rigid_count_gene.rb', line 33

def self.combine(gene_a, _gene_b)
  gene_a
end