# File lib/rantly/generator.rb, line 194 def freq(*pairs) pairs = pairs.map do |pair| case pair when Symbol, String, Proc [1,pair] when Array unless pair.first.is_a?(Integer) [1] + pair else pair end end end total = pairs.inject(0) { |sum,p| sum + p.first } raise(RuntimeError, "Illegal frequency:#{pairs.inspect}") if total == 0 pos = range(1,total) pairs.each do |p| weight, gen, *args = p if pos <= p[0] return self.call(gen,*args) else pos -= weight end end end