class Wordlist::Operators::Power

Lazily enumerates over every combination of words in the wordlist.

@since 1.0.0

Attributes

wordlists[R]

The product of the wordlist with itself.

@return [Product]

Public Class Methods

new(wordlist,exponent) click to toggle source

Initializes the power operator.

@param [Enumerable] wordlist

@param [Integer] exponent

# File lib/wordlist/operators/power.rb, line 28
def initialize(wordlist,exponent)
  super(wordlist,exponent)

  @wordlists = wordlist

  (exponent - 1).times do
    @wordlists = Product.new(wordlist,@wordlists)
  end
end

Public Instance Methods

each(&block) click to toggle source

Enumerates over every combination of words from the wordlist.

@yield [string]

The given block will be passed each combination of words from the
wordlist.

@yieldparam [String] string

A combination of words from the wordlist.

@return [Enumerator]

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

@example

wordlist = Wordlist::Words["foo", "bar"]
(wordlist ** 3).each do |word|
  puts word
end
# foofoofoo
# foofoobar
# foobarfoo
# foobarbar
# barfoofoo
# barfoobar
# barbarfoo
# barbarbar

@api public

# File lib/wordlist/operators/power.rb, line 67
def each(&block)
  @wordlists.each(&block)
end