Method: Wordlist::ListMethods#mutate

Defined in:
lib/wordlist/list_methods.rb

#mutate(pattern, replace = nil) {|match| ... } ⇒ Mutate

Lazily performs every combination of a string substitution on every word in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar", "baz"]
wordlist.mutate(/[oa]/, {'o' => '0', 'a' => '@'}).each do |word|
  puts word
end
# foo
# f0o
# fo0
# f00
# bar
# b@r
# baz
# b@z

Parameters:

  • pattern (Regexp, String)

    The pattern to replace.

  • replace (String, Hash, nil) (defaults to: nil)

    The characters or character range to use as the replacement.

Yields:

  • (match)

    The given block will be call to replace the matched substring, if replace is nil.

Yield Parameters:

  • match (String)

    A matched substring.

Returns:

  • (Mutate)

    The lazy String#gsub modification of the wordlist.

Since:

  • 1.0.0



417
418
419
420
421
422
423
# File 'lib/wordlist/list_methods.rb', line 417

def mutate(pattern,replace=nil,&block)
  if replace
    Modifiers::Mutate.new(self,pattern,replace,&block)
  else
    Modifiers::Mutate.new(self,pattern,&block)
  end
end