Class: RBS::TypeName

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/type_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace:, name:) ⇒ TypeName

Returns a new instance of TypeName.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rbs/type_name.rb', line 8

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

#kindObject (readonly)

Returns the value of attribute kind.



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

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

Instance Method Details

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



24
25
26
# File 'lib/rbs/type_name.rb', line 24

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

#absolute!Object



54
55
56
# File 'lib/rbs/type_name.rb', line 54

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

#absolute?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/rbs/type_name.rb', line 58

def absolute?
  namespace.absolute?
end

#alias?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rbs/type_name.rb', line 50

def alias?
  kind == :alias
end

#class?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rbs/type_name.rb', line 46

def class?
  kind == :class
end

#hashObject



30
31
32
# File 'lib/rbs/type_name.rb', line 30

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

#interface?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/rbs/type_name.rb', line 66

def interface?
  kind == :interface
end

#relative!Object



62
63
64
# File 'lib/rbs/type_name.rb', line 62

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

#to_json(*a) ⇒ Object



38
39
40
# File 'lib/rbs/type_name.rb', line 38

def to_json(*a)
  to_s.to_json(*a)
end

#to_namespaceObject



42
43
44
# File 'lib/rbs/type_name.rb', line 42

def to_namespace
  namespace.append(self.name)
end

#to_sObject



34
35
36
# File 'lib/rbs/type_name.rb', line 34

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

#with_prefix(namespace) ⇒ Object



70
71
72
# File 'lib/rbs/type_name.rb', line 70

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