Class: RBS::TypeName
- Inherits:
-
Object
- Object
- RBS::TypeName
- Defined in:
- lib/rbs/type_name.rb
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #absolute! ⇒ Object
- #absolute? ⇒ Boolean
- #alias? ⇒ Boolean
- #class? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(namespace:, name:) ⇒ TypeName
constructor
A new instance of TypeName.
- #interface? ⇒ Boolean
- #relative! ⇒ Object
- #split ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_namespace ⇒ Object
- #to_s ⇒ Object
- #with_prefix(namespace) ⇒ Object
Constructor Details
#initialize(namespace:, name:) ⇒ TypeName
Returns a new instance of TypeName.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rbs/type_name.rb', line 9 def initialize(namespace:, name:) @namespace = namespace @name = name @kind = case when name.match?(/\A[A-Z]/) :class when name.match?(/\A[a-z]/) :alias when name.start_with?("_") :interface else # Defaults to :class :class end end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
7 8 9 |
# File 'lib/rbs/type_name.rb', line 7 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rbs/type_name.rb', line 6 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/rbs/type_name.rb', line 5 def namespace @namespace end |
Instance Method Details
#+(other) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rbs/type_name.rb', line 79 def +(other) if other.absolute? other else TypeName.new( namespace: self.to_namespace + other.namespace, name: other.name ) end end |
#==(other) ⇒ Object Also known as: eql?
25 26 27 |
# File 'lib/rbs/type_name.rb', line 25 def ==(other) other.is_a?(self.class) && other.namespace == namespace && other.name == name end |
#absolute! ⇒ Object
55 56 57 |
# File 'lib/rbs/type_name.rb', line 55 def absolute! self.class.new(namespace: namespace.absolute!, name: name) end |
#absolute? ⇒ Boolean
59 60 61 |
# File 'lib/rbs/type_name.rb', line 59 def absolute? namespace.absolute? end |
#alias? ⇒ Boolean
51 52 53 |
# File 'lib/rbs/type_name.rb', line 51 def alias? kind == :alias end |
#class? ⇒ Boolean
47 48 49 |
# File 'lib/rbs/type_name.rb', line 47 def class? kind == :class end |
#hash ⇒ Object
31 32 33 |
# File 'lib/rbs/type_name.rb', line 31 def hash namespace.hash ^ name.hash end |
#interface? ⇒ Boolean
67 68 69 |
# File 'lib/rbs/type_name.rb', line 67 def interface? kind == :interface end |
#relative! ⇒ Object
63 64 65 |
# File 'lib/rbs/type_name.rb', line 63 def relative! self.class.new(namespace: namespace.relative!, name: name) end |
#split ⇒ Object
75 76 77 |
# File 'lib/rbs/type_name.rb', line 75 def split namespace.path + [name] end |
#to_json(state = _ = nil) ⇒ Object
39 40 41 |
# File 'lib/rbs/type_name.rb', line 39 def to_json(state = _ = nil) to_s.to_json(state) end |
#to_namespace ⇒ Object
43 44 45 |
# File 'lib/rbs/type_name.rb', line 43 def to_namespace namespace.append(self.name) end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/rbs/type_name.rb', line 35 def to_s "#{namespace.to_s}#{name}" end |
#with_prefix(namespace) ⇒ Object
71 72 73 |
# File 'lib/rbs/type_name.rb', line 71 def with_prefix(namespace) self.class.new(namespace: namespace + self.namespace, name: name) end |