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

Instance Method Details

#as_wordString

Returns:

  • (String)


15
# File 'sig/lib/rambling/trie/enumerable.rbs', line 15

def as_word: -> String

#children_treeHash[Symbol, Nodes::Node[TValue]]

Returns:



21
# File 'sig/lib/rambling/trie/enumerable.rbs', line 21

def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]

#eachEnumerable[TValue] #eachEnumerator[String, void]

Iterates over the words contained in the trie.

Overloads:

  • #eachEnumerable[TValue]

    Returns:

  • #eachEnumerator[String, void]

    Returns:

    • (Enumerator[String, void])

Yields:

  • (String)

    the words contained in this trie node.

Yield Parameters:

  • arg0 (String)

Yield Returns:

  • (void)

Returns:

  • (self)


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_enumEnumerator[String, void]

Returns a new empty enumerator for early-exit returns. A method rather than a constant to prevent shared mutable state.

Returns:

  • (Enumerator[String, void])


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

Returns:

  • (Boolean)


19
# File 'sig/lib/rambling/trie/enumerable.rbs', line 19

def terminal?: -> bool