In Files

  • rbs-1.0.4/lib/rbs/namespace.rb

Class/Module Index [+]

Quicksearch

RBS::Namespace

Attributes

path[R]

Public Class Methods

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

Public Instance Methods

+(other) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 18
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-1.0.4/lib/rbs/namespace.rb, line 55
def ==(other)
  other.is_a?(Namespace) && other.path == path && other.absolute? == absolute?
end
            
Also aliased as: eql?
absolute!() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 43
def absolute!
  self.class.new(path: path, absolute: true)
end
            
absolute?() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 35
def absolute?
  @absolute
end
            
append(component) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 26
def append(component)
  self.class.new(path: path + [component], absolute: absolute?)
end
            
ascend() click to toggle source
 
               # File rbs-1.0.4/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
            
empty?() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 51
def empty?
  path.empty?
end
            
eql?(other) click to toggle source
Alias for: ==
hash() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 61
def hash
  self.class.hash ^ path.hash ^ absolute?.hash
end
            
parent() click to toggle source
 
               # File rbs-1.0.4/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
            
relative!() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 47
def relative!
  self.class.new(path: path, absolute: false)
end
            
relative?() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 39
def relative?
  !absolute?
end
            
split() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 65
def split
  last = path.last or return
  parent = self.parent
  [parent, last]
end
            
to_s() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 71
def to_s
  if empty?
    absolute? ? "::" : ""
  else
    s = path.join("::")
    absolute? ? "::#{s}::" : "#{s}::"
  end
end
            
to_type_name() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/namespace.rb, line 80
def to_type_name
  parent, name = split

  raise unless name
  raise unless parent

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