lib/key_tree/path.rb in key_tree-0.6.1 vs lib/key_tree/path.rb in key_tree-0.7.0

- old
+ new

@@ -14,11 +14,11 @@ # # Make a new key path from one or more keys or paths # def self.[](*key_paths) key_paths.reduce(Path.new) do |result, key_path| - result << key_path.to_key_path + result << Path.new(key_path) end end # # KeyTree::Path.new(+key_or_path+) @@ -39,13 +39,11 @@ else initialize(key_path.to_key_path) end end - def to_key_path - self - end + alias to_key_path itself def to_s join('.') end @@ -62,23 +60,25 @@ end # Returns a key path without the leading +prefix+ # # :call-seq: - # Path - other => Path - def -(other) + # drop(other) => Path + def drop(other) other = other.to_key_path raise KeyError unless prefix?(other) + super(other.length) end # Is +other+ a prefix? # # :call-seq: # prefix?(other) => boolean 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 alias === prefix?