Sha256: c74255864d0265c11dbca5ca46d23dd5dfb87197c7371600991be28f45b7654e

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'wordlist/modifiers/sub'

module Wordlist
  module Modifiers
    #
    # Lazily calls `String#gsub` on every word in the wordlist.
    #
    # @since 1.0.0
    #
    class Gsub < Sub

      #
      # 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::List["Foo", "BAR", "bAz"]
      #   wordlist.gsub(/o/,'0').each do |word|
      #     puts word
      #   end
      #   # f00
      #   # bar
      #   # baz
      #
      # @api public
      #
      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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wordlist-1.0.0 lib/wordlist/modifiers/gsub.rb