class GeneGenie::SimpleGeneMutator

A SimpleGeneMutator loops through each member of a hash, and has a 1% chance of swapping the value for another valid value (based on the template) @since 0.0.1

Public Class Methods

new(template, mutation_rate = 0.01) click to toggle source
# File lib/gene_genie/mutator/simple_gene_mutator.rb, line 7
def initialize(template, mutation_rate = 0.01)
  @template = template
  @mutation_rate = mutation_rate
end

Public Instance Methods

call(genes) click to toggle source
# File lib/gene_genie/mutator/simple_gene_mutator.rb, line 12
def call(genes)
  genes.each_with_index do |hash, index|
    hash.each do |k, v|
      if rand < @mutation_rate
        hash[k] = rand(@template[index][k])
      end
    end
  end
  genes
end