Method: Wordlist::Operators::Unique#each

Defined in:
lib/wordlist/operators/unique.rb

#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