Method: Wordlist::Modifiers::Sub#initialize

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

#initialize(wordlist, pattern, replace = nil) {|match| ... } ⇒ Sub

Initializes the String#sub modifier.

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.

Raises:

  • (TypeError)

    The replace value was not a String, Hash, or nil.

Since:

  • 1.0.0



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wordlist/modifiers/sub.rb', line 47

def initialize(wordlist,pattern,replace=nil,&block)
  super(wordlist)

  @pattern = pattern
  @replace = case replace
             when String, Hash, nil then replace
             else
               raise(TypeError,"no implicit conversion of #{replace.class} to String")
             end
  @block   = block
end