Class: Decode::Trie::Node
- Inherits:
-
Object
- Object
- Decode::Trie::Node
- Defined in:
- lib/decode/trie.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize ⇒ Node
constructor
A new instance of Node.
- #lookup(path, index = 0) ⇒ Object
- #traverse(path = []) {|path, values| ... } ⇒ Object
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
26 27 28 29 |
# File 'lib/decode/trie.rb', line 26 def initialize @values = nil @children = Hash.new end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
32 33 34 |
# File 'lib/decode/trie.rb', line 32 def children @children end |
#values ⇒ Object
Returns the value of attribute values.
31 32 33 |
# File 'lib/decode/trie.rb', line 31 def values @values end |
Instance Method Details
#lookup(path, index = 0) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/decode/trie.rb', line 34 def lookup(path, index = 0) if index < path.size if child = @children[path[index]] return child.lookup(path, index+1) end else return self end end |
#traverse(path = []) {|path, values| ... } ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/decode/trie.rb', line 44 def traverse(path = [], &block) yield path, values if values @children.each do |name, node| node.traverse([*path, name], &block) end end |