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.

Instance Method Summary collapse

Instance Method Details

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

Iterates over the words contained in the trie.

Yields:

  • (String)

    the words contained in this trie node.



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

def each
  return enum_for :each unless block_given?

  yield as_word if terminal?

  children_tree.each_value do |child|
    child.each do |word|
      yield word
    end
  end
end