Class: VGen::ArrayGen
- Inherits:
-
Object
- Object
- VGen::ArrayGen
- Defined in:
- lib/v_gen/array_gen.rb,
lib/v_gen/old_array_gen.rb
Instance Method Summary collapse
- #call(only: [ IntGen.new, FloatGen.new, VarWordGen.new, self.class.new, KeywordGen.new ], except: [], min: 4, max: 8) ⇒ Object
-
#initialize(max_depth: 3) ⇒ ArrayGen
constructor
A new instance of ArrayGen.
Constructor Details
#initialize(max_depth: 3) ⇒ ArrayGen
Returns a new instance of ArrayGen.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/v_gen/array_gen.rb', line 3 def initialize( uniq: false, min: 4, max: 9, length: nil, size: nil, gens: [ proc {Random.new.rand} ] ) @uniq = uniq @length = length || size || (min..max) @gens = gens @min = min @max = max end |
Instance Method Details
#call(only: [ IntGen.new, FloatGen.new, VarWordGen.new, self.class.new, KeywordGen.new ], except: [], min: 4, max: 8) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/v_gen/array_gen.rb', line 18 def call() used_values = [] Array.new(array_length) { loop do candidate_value = @gens.sample.call if used_values.include?(candidate_value) next else used_values << candidate_value if @uniq break candidate_value end end } end |