123456789_123456789_123456789_123456789_123456789_

Class: RBS::TypeName

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/type_name.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(namespace:, name:) ⇒ TypeName

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 7

def initialize(namespace:, name:)
  @namespace = namespace
  @name = name
  @kind = case name.to_s[0,1]
          when /[A-Z]/
            :class
          when /[a-z]/
            :alias
          when "_"
            :interface
          else
            # Defaults to :class
            :class
          end
end

Instance Attribute Details

#absolute?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 57

def absolute?
  namespace.absolute?
end

#alias?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 49

def alias?
  kind == :alias
end

#class?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 45

def class?
  kind == :class
end

#interface?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 65

def interface?
  kind == :interface
end

#kind (readonly)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 5

attr_reader :kind

#name (readonly)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 4

attr_reader :name

#namespace (readonly)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 3

attr_reader :namespace

Instance Method Details

#==(other) Also known as: #eql?

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 23

def ==(other)
  other.is_a?(self.class) && other.namespace == namespace && other.name == name
end

#absolute!

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 53

def absolute!
  self.class.new(namespace: namespace.absolute!, name: name)
end

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 27

alias eql? ==

#hash

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 29

def hash
  self.class.hash ^ namespace.hash ^ name.hash
end

#relative!

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 61

def relative!
  self.class.new(namespace: namespace.relative!, name: name)
end

#to_json(state = _ = nil)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 37

def to_json(state = _ = nil)
  to_s.to_json(state)
end

#to_namespace

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 41

def to_namespace
  namespace.append(self.name)
end

#to_s

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 33

def to_s
  "#{namespace.to_s}#{name}"
end

#with_prefix(namespace)

[ GitHub ]

  
# File 'lib/rbs/type_name.rb', line 69

def with_prefix(namespace)
  self.class.new(namespace: namespace + self.namespace, name: name)
end