Class: Wordlist::Modifiers::Mutate
- Defined in:
- lib/wordlist/modifiers/mutate.rb
Overview
Lazily enumerates through every combination of a string substitution on every word in the wordlist.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Sub
Attributes inherited from Modifier
Instance Method Summary collapse
-
#each {|word| ... } ⇒ Enumerator
Enumerates over every mutation of every word in the wordlist.
Methods inherited from Sub
Methods inherited from Modifier
Constructor Details
This class inherits a constructor from Wordlist::Modifiers::Sub
Instance Method Details
#each {|word| ... } ⇒ Enumerator
Enumerates over every mutation of every word in the wordlist.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/wordlist/modifiers/mutate.rb', line 42 def each return enum_for(__method__) unless block_given? @wordlist.each do |word| yield word matches = all_matches(word) each_combination(matches) do |selected_matches| new_word = word.dup offset = 0 selected_matches.each do |match| index, end_index = match.offset(0) length = end_index - index matched_string = match[0] replace_string = substitute(matched_string) new_word[index+offset,length] = replace_string offset += (replace_string.length - length) end yield new_word end end end |