Skip to content

Commit 23ce5e0

Browse files
committed
Add community methods for accessing populations and evolving them collectively.
1 parent 2acae82 commit 23ce5e0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/evolvable/community.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ def populations_by_name
9797
@populations_by_name ||= self.class.populations_by_name.dup
9898
end
9999

100+
# Returns an array of population instances
101+
# @return [Array] An array of population instances
102+
def populations
103+
populations_by_name.values
104+
end
105+
106+
# Evolves all populations in the community
107+
# @return [void]
108+
def evolve(...)
109+
populations.each { |population| population.evolve(...) }
110+
end
111+
100112
# Resets the populations hash to an empty hash
101113
# @return [Hash] An empty hash
102114
def reset_populations

0 commit comments

Comments
 (0)