class KeyTree::Path
Representation of the key path to a value in a key tree
Public Class Methods
[](*key_paths)
click to toggle source
KeyTree::Path[key_or_path
, …]
Make a new key path from one or more keys or paths
# File lib/key_tree/path.rb, line 17 def self.[](*key_paths) key_paths.reduce(Path.new) do |result, key_path| result << Path.new(key_path) end end
new(key_path = [])
click to toggle source
KeyTree::Path.new
(key_or_path
)
Make a new key path from a dot separated string, single symbol, or array of strings or symbols.
Example:
KeyTree::Path.new("a.b.c") => [:a, :b, :c]
Calls superclass method
# File lib/key_tree/path.rb, line 33 def initialize(key_path = []) key_path = key_path.to_key_path unless key_path.is_a? Array super(key_path.map(&:to_sym)) end
Public Instance Methods
+(other)
click to toggle source
# File lib/key_tree/path.rb, line 53 def +(other) dup.concat(other.to_key_path) end
<<(other)
click to toggle source
# File lib/key_tree/path.rb, line 49 def <<(other) concat(other.to_key_path) end
Alias for: prefix?
conflict?(other)
click to toggle source
Would other
conflict?
# File lib/key_tree/path.rb, line 83 def conflict?(other) prefix?(other) || other.prefix?(self) if self != other end
drop(other) → Path
click to toggle source
Returns a key path without the leading prefix
Calls superclass method
# File lib/key_tree/path.rb, line 61 def drop(other) other = other.to_key_path raise KeyError unless prefix?(other) super(other.length) end
inspect()
click to toggle source
# File lib/key_tree/path.rb, line 45 def inspect %("#{self}") end
prefix?(other) → boolean
click to toggle source
Is other
a prefix?
# File lib/key_tree/path.rb, line 72 def prefix?(other) other = other.to_key_path return false if other.length > length key_enum = each other.all? { |other_key| key_enum.next == other_key } end
Also aliased as: ===
to_s()
click to toggle source
# File lib/key_tree/path.rb, line 41 def to_s join('.') end