module Stig module Generators module Array # Public: Generates an random Array. Elements are generated by a # generator. Size is variable, use a Range with equal start and end for a # fixed size. # # generator - An object implementing #call or #random. # size - A maximum size Integer or Range (default: 1..10). # # Returns an Array. # Raises ArgumentError when an invalid generator was supplied. def self.random(generator, size = 1..10) unless generator.respond_to?(:call) || generator.respond_to?(:random) msg = "no #call or #random implemented for #{generator}" raise ArgumentError, msg end method = generator.respond_to?(:call) ? :call : :random array = [] rand(size).times do array << generator.send(method) end array end end end end