Module: Evolvable::GeneCluster::ClassMethods

Defined in:
lib/evolvable/gene_cluster.rb

Overview

Class methods added to classes that include Evolvable::GeneCluster

Instance Method Summary collapse

Instance Method Details

#apply_cluster(evolvable_class, cluster_name, **_) ⇒ void

This method returns an undefined value.

Applies all genes in this cluster to the given evolvable class. This is called automatically when using the cluster macro.

Parameters:

  • evolvable_class (Class)

    The evolvable class to apply the cluster to

  • cluster_name (Symbol)

    The name to use for the cluster in the evolvable class

  • _ (Hash)

    Additional options (for future expansion)



88
89
90
91
92
# File 'lib/evolvable/gene_cluster.rb', line 88

def apply_cluster(evolvable_class, cluster_name, **_)
  @cluster_config.each do |name, kw|
    evolvable_class.gene("#{cluster_name}-#{name}", **kw, cluster: cluster_name)
  end
end

#gene(name, **opts) ⇒ Object

Defines a gene in the cluster. This is used internally by the cluster to define its component genes.

Parameters:

  • name (Symbol)

    The name of the gene within the cluster

  • opts (Hash)

    Options for the gene (type, count, etc.)



75
76
77
# File 'lib/evolvable/gene_cluster.rb', line 75

def gene(name, **opts)
  @cluster_config << [name, opts]
end

#inherited(subclass) ⇒ void

This method returns an undefined value.

Ensures that subclasses inherit the cluster configuration.

Parameters:

  • subclass (Class)

    The subclass that is inheriting from this class



100
101
102
103
# File 'lib/evolvable/gene_cluster.rb', line 100

def inherited(subclass)
  super
  subclass.instance_variable_set(:@cluster_config, @cluster_config.dup)
end