Module: Rambling::Trie::Enumerable
- Includes:
- Enumerable, Enumerable[String]
- Included in:
- Nodes::Node
- Defined in:
- lib/rambling/trie/enumerable.rb,
sig/lib/rambling/trie/enumerable.rbs
Overview
Provides enumerable behavior to the trie data structure.
Instance Method Summary collapse
- #as_word ⇒ String
- #children_tree ⇒ Hash[Symbol, Nodes::Node[TValue]]
-
#each {|String| ... } ⇒ self
Iterates over the words contained in the trie.
-
#empty_enum ⇒ Enumerator[String, void]
Returns a new empty enumerator for early-exit returns.
- #terminal? ⇒ Boolean
Instance Method Details
#as_word ⇒ String
15 |
# File 'sig/lib/rambling/trie/enumerable.rbs', line 15
def as_word: -> String
|
#children_tree ⇒ Hash[Symbol, Nodes::Node[TValue]]
21 |
# File 'sig/lib/rambling/trie/enumerable.rbs', line 21
def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]
|
#each ⇒ Enumerable[TValue] #each ⇒ Enumerator[String, void]
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 ⇒ Enumerator[String, void]
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 |
#terminal? ⇒ Boolean
19 |
# File 'sig/lib/rambling/trie/enumerable.rbs', line 19
def terminal?: -> bool
|