Class: Wordlist::Modifiers::Gsub

Inherits:
Sub show all
Defined in:
lib/wordlist/modifiers/gsub.rb

Overview

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

Since:

  • 1.0.0

Instance Attribute Summary

Attributes inherited from Sub

#block, #pattern, #replace

Attributes inherited from Modifier

#wordlist

Instance Method Summary collapse

Methods inherited from Sub

#initialize

Methods inherited from Modifier

#initialize

Constructor Details

This class inherits a constructor from Wordlist::Modifiers::Sub

Instance Method Details

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

Enumerates over every gsubed word in the wordlist.

Examples:

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

Yields:

  • (word)

    The given block will be passed each gsubed word.

Yield Parameters:

  • word (String)

    A gsubed word from the wordlist.

Returns:

  • (Enumerator)

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

Since:

  • 1.0.0



36
37
38
39
40
41
42
43
44
45
46
47
48
# 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