Class: Matchers::Trie::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Returns a new instance of Node.



48
49
50
51
# File 'lib/matcher.rb', line 48

def initialize
  @children = {}
  @children.default = nil
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



46
47
48
# File 'lib/matcher.rb', line 46

def children
  @children
end

Instance Method Details

#forward(str) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/matcher.rb', line 58

def forward(str)
  children = @children
  child = nil
  str.chars.each do |char|
    child = children[char]
    children = child.children
  end
  child
end

#insert(char) ⇒ Object



53
54
55
56
# File 'lib/matcher.rb', line 53

def insert(char)
  @children[char] = Node.new unless @children.key?(char)
  @children[char]
end