Method: Wordlist::ListMethods#sub

Defined in:
lib/wordlist/list_methods.rb

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

Lazily calls String#sub on each word in the wordlist.

Examples:

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

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:

  • (Sub)

    The lazy String#sub modification of the wordlist.

Since:

  • 1.0.0



272
273
274
275
276
277
278
# File 'lib/wordlist/list_methods.rb', line 272

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