Class: Dry::Validation::Rust::PathTrie
- Inherits:
-
Object
- Object
- Dry::Validation::Rust::PathTrie
- Defined in:
- lib/dry/validation/rust/path_trie.rb
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #add(path) ⇒ Object
- #freeze ⇒ Object
- #hash ⇒ Object
-
#initialize ⇒ PathTrie
constructor
A new instance of PathTrie.
- #prefix?(path) ⇒ Boolean
Constructor Details
#initialize ⇒ PathTrie
Returns a new instance of PathTrie.
10 11 12 |
# File 'lib/dry/validation/rust/path_trie.rb', line 10 def initialize @root = {} end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
38 39 40 |
# File 'lib/dry/validation/rust/path_trie.rb', line 38 def ==(other) other.is_a?(self.class) && @root == other.instance_variable_get(:@root) end |
#add(path) ⇒ Object
14 15 16 17 18 |
# File 'lib/dry/validation/rust/path_trie.rb', line 14 def add(path) node = @root path.each { |part| node = node[part] ||= {} } node[TERMINAL] = true end |
#freeze ⇒ Object
33 34 35 36 |
# File 'lib/dry/validation/rust/path_trie.rb', line 33 def freeze freeze_node(@root) super end |
#hash ⇒ Object
44 45 46 |
# File 'lib/dry/validation/rust/path_trie.rb', line 44 def hash @root.hash end |
#prefix?(path) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dry/validation/rust/path_trie.rb', line 20 def prefix?(path) return false if path.empty? node = @root path.each do |part| return true if node.key?(TERMINAL) node = node[part] return false unless node end true end |