Module: Evolvable::GeneCluster
- Defined in:
- lib/evolvable/gene_cluster.rb
Overview
Gene clusters group related genes into reusable components that can be applied to multiple evolvable classes. This promotes clean organization, eliminates naming conflicts, and simplifies gene access.
Benefits:
- Reuse gene groups across multiple evolvables
- Prevent name collisions via automatic namespacing
- Treat clusters as structured subcomponents of a genome
- Access all genes in a cluster with a single method call
The ColorPaletteCluster
below defines a group of genes commonly used for styling themes:
class ColorPaletteCluster
include Evolvable::GeneCluster
gene :primary, type: 'ColorGene', count: 1
gene :secondary, type: 'ColorGene', count: 1
gene :accent, type: 'ColorGene', count: 1
gene :neutral, type: 'ColorGene', count: 1
end
Use the cluster
macro to apply the cluster to your evolvable class:
class Theme
include Evolvable
cluster :colors, type: ColorPaletteCluster
def inspect_colors
colors.join(", ")
end
end
When a cluster is applied, its genes are automatically namespaced with the cluster name:
- Access the full group:
theme.colors
→ returns all genes in the colors cluster - Access individual genes:
theme.find_gene("colors-primary")
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ void
When included in a class, extends the class with ClassMethods and initializes the cluster configuration.
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
When included in a class, extends the class with ClassMethods and initializes the cluster configuration. This is called automatically when you include the GeneCluster module in your class.
59 60 61 62 |
# File 'lib/evolvable/gene_cluster.rb', line 59 def self.included(base) base.extend(ClassMethods) base.instance_variable_set(:@cluster_config, []) end |