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 (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
- #to_json(*a) ⇒ Object
- #to_namespace ⇒ Object
- #to_s ⇒ Object
- #with_prefix(namespace) ⇒ Object
Constructor Details
#initialize(namespace:, name:) ⇒ TypeName
Returns a new instance of TypeName.
7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 end end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
5 6 7 |
# File 'lib/rbs/type_name.rb', line 5 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/rbs/type_name.rb', line 4 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/rbs/type_name.rb', line 3 def namespace @namespace end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
20 21 22 |
# File 'lib/rbs/type_name.rb', line 20 def ==(other) other.is_a?(self.class) && other.namespace == namespace && other.name == name end |
#absolute! ⇒ Object
50 51 52 |
# File 'lib/rbs/type_name.rb', line 50 def absolute! self.class.new(namespace: namespace.absolute!, name: name) end |
#absolute? ⇒ Boolean
54 55 56 |
# File 'lib/rbs/type_name.rb', line 54 def absolute? namespace.absolute? end |
#alias? ⇒ Boolean
46 47 48 |
# File 'lib/rbs/type_name.rb', line 46 def alias? kind == :alias end |
#class? ⇒ Boolean
42 43 44 |
# File 'lib/rbs/type_name.rb', line 42 def class? kind == :class end |
#hash ⇒ Object
26 27 28 |
# File 'lib/rbs/type_name.rb', line 26 def hash self.class.hash ^ namespace.hash ^ name.hash end |
#interface? ⇒ Boolean
62 63 64 |
# File 'lib/rbs/type_name.rb', line 62 def interface? kind == :interface end |
#relative! ⇒ Object
58 59 60 |
# File 'lib/rbs/type_name.rb', line 58 def relative! self.class.new(namespace: namespace.relative!, name: name) end |
#to_json(*a) ⇒ Object
34 35 36 |
# File 'lib/rbs/type_name.rb', line 34 def to_json(*a) to_s.to_json(*a) end |
#to_namespace ⇒ Object
38 39 40 |
# File 'lib/rbs/type_name.rb', line 38 def to_namespace namespace.append(self.name) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/rbs/type_name.rb', line 30 def to_s "#{namespace.to_s}#{name}" end |
#with_prefix(namespace) ⇒ Object
66 67 68 |
# File 'lib/rbs/type_name.rb', line 66 def with_prefix(namespace) self.class.new(namespace: namespace + self.namespace, name: name) end |