class Steep::AST::Namespace
def self.empty
def self.empty new(path: [], absolute: false) end
def self.parse(string)
def self.parse(string) if string.start_with?("::") new(path: string.split("::").drop(1).map(&:to_sym), absolute: true) else new(path: string.split("::").map(&:to_sym), absolute: false) end end
def self.root
def self.root new(path: [], absolute: true) end
def +(other)
def +(other) if other.absolute? other else self.class.new(path: path + other.path, absolute: absolute?) end end
def ==(other)
def ==(other) other.is_a?(Namespace) && other.path == path && other.absolute? == absolute? end
def absolute!
def absolute! self.class.new(path: path, absolute: true) end
def absolute?
def absolute? @absolute end
def append(component)
def append(component) self.class.new(path: path + [component], absolute: absolute?) end
def empty?
def empty? path.empty? end
def hash
def hash self.class.hash ^ path.hash ^ absolute?.hash end
def initialize(path:, absolute:)
def initialize(path:, absolute:) @path = path @absolute = absolute end
def parent
def parent raise "Parent with empty namespace" if empty? self.class.new(path: path.take(path.size - 1), absolute: absolute?) end
def relative?
def relative? !absolute? end
def to_s
def to_s if empty? absolute? ? "::" : "" else s = path.join("::") absolute? ? "::#{s}::" : "#{s}::" end end