class Wordlist::Modifiers::Gsub

Lazily calls ‘String#gsub` on every word in the wordlist.

@since 1.0.0

Public Instance Methods

each() { |gsub| ... } click to toggle source

Enumerates over every ‘gsub`ed word in the wordlist.

@yield [word]

The given block will be passed each `gsub`ed word.

@yieldparam [String] word

A `gsub`ed word from the wordlist.

@return [Enumerator]

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

@example

wordlist = Wordlist::Words["Foo", "BAR", "bAz"]
wordlist.gsub(/o/,'0').each do |word|
  puts word
end
# f00
# bar
# baz

@api public

# File lib/wordlist/modifiers/gsub.rb, line 36
def each
  return enum_for(__method__) unless block_given?

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