Sha256: ee7e19bacf1e8fb159170ebc1eec5abc39d88d7f03e29e81e327bc8069967de8
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
require 'wordlist/operators/binary_operator' require 'wordlist/operators/product' module Wordlist module Operators # # Lazily enumerates over every combination of words in the wordlist. # # @since 1.0.0 # class Power < BinaryOperator # The product of the wordlist with itself. # # @return [Product] attr_reader :wordlists alias exponent right # # Initializes the power operator. # # @param [Enumerable] wordlist # # @param [Integer] exponent # def initialize(wordlist,exponent) super(wordlist,exponent) @wordlists = wordlist (exponent - 1).times do @wordlists = Product.new(wordlist,@wordlists) end end # # 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::List["foo", "bar"] # (wordlist ** 3).each do |word| # puts word # end # # foofoofoo # # foofoobar # # foobarfoo # # foobarbar # # barfoofoo # # barfoobar # # barbarfoo # # barbarbar # # @api public # def each(&block) @wordlists.each(&block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wordlist-1.0.0 | lib/wordlist/operators/power.rb |