Method: Wordlist::Modifiers::Sub#each

Defined in:
lib/wordlist/modifiers/sub.rb

#each {|word| ... } ⇒ Enumerator

Enumerates over every subed word in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar", "baz"]
wordlist.sub(/o/, '0').each do |word|
  puts word
end
# f0o
# bar
# baz

Yields:

  • (word)

    The given block will be passed each subed word.

Yield Parameters:

  • word (String)

    A subed word.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.

Since:

  • 1.0.0



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/wordlist/modifiers/sub.rb', line 82

def each
  return enum_for(__method__) unless block_given?

  if @replace
    @wordlist.each do |word|
      yield word.sub(@pattern,@replace)
    end
  else
    @wordlist.each do |word|
      yield word.sub(@pattern,&block)
    end
  end
end