Object
# File rbs-1.4.0/lib/rbs/namespace.rb, line 10
def self.empty
new(path: [], absolute: false)
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 5
def initialize(path:, absolute:)
@path = path
@absolute = absolute
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 18
def +(other)
if other.absolute?
other
else
self.class.new(path: path + other.path, absolute: absolute?)
end
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 55
def ==(other)
other.is_a?(Namespace) && other.path == path && other.absolute? == absolute?
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 43
def absolute!
self.class.new(path: path, absolute: true)
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 35
def absolute?
@absolute
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 26
def append(component)
self.class.new(path: path + [component], absolute: absolute?)
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 97
def ascend
if block_given?
current = self
until current.empty?
yield current
current = _ = current.parent
end
yield current
self
else
enum_for(:ascend)
end
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 51
def empty?
path.empty?
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 61
def hash
self.class.hash ^ path.hash ^ absolute?.hash
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 30
def parent
raise "Parent with empty namespace" if empty?
self.class.new(path: path.take(path.size - 1), absolute: absolute?)
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 47
def relative!
self.class.new(path: path, absolute: false)
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 39
def relative?
!absolute?
end
# File rbs-1.4.0/lib/rbs/namespace.rb, line 65
def split
last = path.last or return
parent = self.parent
[parent, last]
end