Module: Rambling::Trie::Enumerable

Includes:
Enumerable
Included in:
Nodes::Node
Defined in:
lib/rambling/trie/enumerable.rb

Overview

Provides enumerable behavior to the trie data structure.

Constant Summary collapse

EMPTY_ENUMERATOR =

Empty enumerator constant for early each exits.

[].to_enum :each

Instance Method Summary collapse

Instance Method Details

#each {|String| ... } ⇒ self

Iterates over the words contained in the trie.

Yields:

  • (String)

    the words contained in this trie node.

Returns:

  • (self)


19
20
21
22
23
24
25
26
27
# File 'lib/rambling/trie/enumerable.rb', line 19

def each
  return enum_for :each unless block_given?

  yield as_word if terminal?

  children_tree.each_value { |child| child.each { |word| yield word } }

  self
end