Module: Rambling::Trie::Enumerable
Overview
Provides enumerable behavior to the trie data structure.
Instance Method Summary collapse
-
#each {|String| ... } ⇒ self
Iterates over the words contained in the trie.
-
#empty_enum ⇒ Object
Returns a new empty enumerator for early-exit returns.
Instance Method Details
#each {|String| ... } ⇒ self
Iterates over the words contained in the trie.
16 17 18 19 20 21 22 23 24 |
# 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 { |child| child.each { |word| yield word } } self end |
#empty_enum ⇒ Object
Returns a new empty enumerator for early-exit returns. A method rather than a constant to prevent shared mutable state.
28 29 30 31 32 |
# File 'lib/rambling/trie/enumerable.rb', line 28 def empty_enum # @type var empty_array: Array[String] empty_array = [] empty_array.each end |