Module: Rambling::Trie::Stringifyable

Included in:
Nodes::Node
Defined in:
lib/rambling/trie/stringifyable.rb

Overview

Provides the ‘String` representation behavior for the trie data structure.

Instance Method Summary collapse

Instance Method Details

#as_wordString

String representation of the current node, if it is a terminal node.

Returns:

  • (String)

    the string representation of the current node.

Raises:



10
11
12
13
14
# File 'lib/rambling/trie/stringifyable.rb', line 10

def as_word
  raise Rambling::Trie::InvalidOperation, 'Cannot represent branch as a word' if letter && !terminal?

  to_s
end

#to_sString

String representation of the current node.

Returns:

  • (String)

    the string representation of the current node.



18
19
20
# File 'lib/rambling/trie/stringifyable.rb', line 18

def to_s
  parent.to_s + letter.to_s
end