Class: RubyLsp::Requests::Support::PrefixTree::Node

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/requests/support/prefix_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Node

Returns a new instance of Node.



59
60
61
62
63
# File 'lib/ruby_lsp/requests/support/prefix_tree.rb', line 59

def initialize(value)
  @children = T.let({}, T::Hash[String, Node])
  @value = T.let(value, String)
  @leaf = T.let(false, T::Boolean)
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



50
51
52
# File 'lib/ruby_lsp/requests/support/prefix_tree.rb', line 50

def children
  @children
end

#leafObject

Returns the value of attribute leaf.



56
57
58
# File 'lib/ruby_lsp/requests/support/prefix_tree.rb', line 56

def leaf
  @leaf
end

#valueObject (readonly)

Returns the value of attribute value.



53
54
55
# File 'lib/ruby_lsp/requests/support/prefix_tree.rb', line 53

def value
  @value
end

Instance Method Details

#collectObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/ruby_lsp/requests/support/prefix_tree.rb', line 66

def collect
  result = T.let([], T::Array[String])
  result << value if leaf

  children.each_value do |node|
    result.concat(node.collect)
  end

  result
end