Class: WordGen::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/word_gen/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word_length, character_set, writer = $stdout) ⇒ Generator

Returns a new instance of Generator.



5
6
7
8
9
10
11
# File 'lib/word_gen/generator.rb', line 5

def initialize word_length, character_set, writer = $stdout
  @word_length, @character_set, @writer = Integer(word_length), character_set.map(&:to_s), writer

  if @word_length < 1
    fail ArgumentError, 'word_length need to be positibe'
  end
end

Instance Attribute Details

#character_setObject (readonly)

Returns the value of attribute character_set.



3
4
5
# File 'lib/word_gen/generator.rb', line 3

def character_set
  @character_set
end

#word_lengthObject (readonly)

Returns the value of attribute word_length.



3
4
5
# File 'lib/word_gen/generator.rb', line 3

def word_length
  @word_length
end

#writerObject (readonly)

Returns the value of attribute writer.



3
4
5
# File 'lib/word_gen/generator.rb', line 3

def writer
  @writer
end

Instance Method Details

#startObject



13
14
15
# File 'lib/word_gen/generator.rb', line 13

def start
  printAllKLengthRec character_set, "", character_set.size, word_length
end