Class: EenieMeenie::Sorters::RoundRobin
- Defined in:
- lib/eenie_meenie/sorters/round_robin.rb
Instance Method Summary collapse
-
#initialize(*args, options) ⇒ RoundRobin
constructor
A new instance of RoundRobin.
- #sort ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*args, options) ⇒ RoundRobin
Returns a new instance of RoundRobin.
4 5 6 |
# File 'lib/eenie_meenie/sorters/round_robin.rb', line 4 def initialize(*args, ) (:groups, :population, ) end |
Instance Method Details
#sort ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/eenie_meenie/sorters/round_robin.rb', line 8 def sort results = {} @groups.each { |group| results.merge!(group => 0) } @population.times do |i| results[@groups[i % @groups.length]] += 1 end groups = results end |