Class: Wordlist::Operators::Unique

Inherits:
UnaryOperator show all
Defined in:
lib/wordlist/operators/unique.rb

Overview

Lazily enumerates over only the unique words in the wordlist, filtering out duplicates.

Since:

  • 1.0.0

Instance Attribute Summary

Attributes inherited from UnaryOperator

#wordlist

Instance Method Summary collapse

Methods inherited from UnaryOperator

#initialize

Constructor Details

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

Instance Method Details

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

Enumerates over the unique words in the wordlist.

Examples:

wordlist= Wordlist::Words["foo", "bar", "baz", "qux"]
(wordlist + wordlist).uniq.each do |word|
  puts word
end
# foo
# bar
# baz
# qux

Yields:

  • (word)

    The given block will be passed each unique word from the wordlist.

Yield Parameters:

  • word (String)

    A unique word from the wordlist.

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
48
49
# File 'lib/wordlist/operators/unique.rb', line 39

def each
  return enum_for(__method__) unless block_given?

  unique_filter = UniqueFilter.new

  @wordlist.each do |word|
    if unique_filter.add?(word)
      yield word
    end
  end
end