Class: Matchers::Trie::Node
- Inherits:
-
Object
- Object
- Matchers::Trie::Node
- Defined in:
- lib/matcher.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #forward(str) ⇒ Object
-
#initialize ⇒ Node
constructor
A new instance of Node.
- #insert(char) ⇒ Object
Constructor Details
#initialize ⇒ Node
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
#children ⇒ Object (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 |