Class: Wordlist::Operators::Product

Inherits:
BinaryOperator show all
Defined in:
lib/wordlist/operators/product.rb

Overview

Lazily enumerates over the combination of the words from two wordlists.

Since:

  • 1.0.0

Instance Attribute Summary

Attributes inherited from BinaryOperator

#left, #right

Instance Method Summary collapse

Methods inherited from BinaryOperator

#initialize

Constructor Details

This class inherits a constructor from Wordlist::Operators::BinaryOperator

Instance Method Details

#each {|string| ... } ⇒ Enumerator

Enumerates over every combination of the words from the two wordlist.

Examples:

wordlist1 = Wordlist::Words["foo", "bar"]
wordlist2 = Wordlist::Words["ABC", "XYZ"]
(wordlist1 * wordlist2).each do |word|
  puts word
end
# fooABC
# fooXYZ
# barABC
# barXYZ

Yields:

  • (string)

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

Yield Parameters:

  • string (String)

    A combination of two words from the two wordlists.

Returns:

  • (Enumerator)

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

Since:

  • 1.0.0



39
40
41
42
43
44
45
46
47
# File 'lib/wordlist/operators/product.rb', line 39

def each
  return enum_for(__method__) unless block_given?

  @left.each do |word1|
    @right.each do |word2|
      yield word1 + word2
    end
  end
end