class RBS::Namespace

Attributes

path[R]

Public Class Methods

empty() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 12
def self.empty
  @empty ||= new(path: [], absolute: false)
end
new(path:, absolute:) click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 7
def initialize(path:, absolute:)
  @path = path
  @absolute = absolute ? true : false
end
parse(string) click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 93
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
root() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 16
def self.root
  @root ||= new(path: [], absolute: true)
end

Public Instance Methods

+(other) click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 20
def +(other)
  if other.absolute?
    other
  else
    self.class.new(path: path + other.path, absolute: absolute?)
  end
end
==(other) click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 59
def ==(other)
  other.is_a?(Namespace) && other.path == path && other.absolute? == absolute?
end
Also aliased as: eql?
absolute!() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 47
def absolute!
  self.class.new(path: path, absolute: true)
end
absolute?() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 39
def absolute?
  @absolute
end
append(component) click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 28
def append(component)
  self.class.new(path: path + [component], absolute: absolute?)
end
ascend() { |current| ... } click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 101
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
empty?() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 55
def empty?
  path.empty?
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 65
def hash
  path.hash ^ absolute?.hash
end
parent() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 32
def parent
  @parent ||= begin
    raise "Parent with empty namespace" if empty?
    self.class.new(path: path.take(path.size - 1), absolute: absolute?)
  end
end
relative!() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 51
def relative!
  self.class.new(path: path, absolute: false)
end
relative?() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 43
def relative?
  !absolute?
end
split() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 69
def split
  last = path.last or return
  parent = self.parent
  [parent, last]
end
to_s() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 75
def to_s
  if empty?
    absolute? ? "::" : ""
  else
    s = path.join("::")
    absolute? ? "::#{s}::" : "#{s}::"
  end
end
to_type_name() click to toggle source
# File rbs-3.6.1/lib/rbs/namespace.rb, line 84
def to_type_name
  parent, name = split

  raise unless name
  raise unless parent

  TypeName.new(name: name, namespace: parent)
end