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(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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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
#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?
23 24 25 |
# File 'lib/rbs/type_name.rb', line 23 def ==(other) other.is_a?(self.class) && other.namespace == namespace && other.name == name end |
#absolute! ⇒ Object
53 54 55 |
# File 'lib/rbs/type_name.rb', line 53 def absolute! self.class.new(namespace: namespace.absolute!, name: name) end |
#absolute? ⇒ Boolean
57 58 59 |
# File 'lib/rbs/type_name.rb', line 57 def absolute? namespace.absolute? end |
#alias? ⇒ Boolean
49 50 51 |
# File 'lib/rbs/type_name.rb', line 49 def alias? kind == :alias end |
#class? ⇒ Boolean
45 46 47 |
# File 'lib/rbs/type_name.rb', line 45 def class? kind == :class end |
#hash ⇒ Object
29 30 31 |
# File 'lib/rbs/type_name.rb', line 29 def hash self.class.hash ^ namespace.hash ^ name.hash end |
#interface? ⇒ Boolean
65 66 67 |
# File 'lib/rbs/type_name.rb', line 65 def interface? kind == :interface end |
#relative! ⇒ Object
61 62 63 |
# File 'lib/rbs/type_name.rb', line 61 def relative! self.class.new(namespace: namespace.relative!, name: name) end |
#to_json(state = _ = nil) ⇒ Object
37 38 39 |
# File 'lib/rbs/type_name.rb', line 37 def to_json(state = _ = nil) to_s.to_json(state) end |
#to_namespace ⇒ Object
41 42 43 |
# File 'lib/rbs/type_name.rb', line 41 def to_namespace namespace.append(self.name) end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/rbs/type_name.rb', line 33 def to_s "#{namespace.to_s}#{name}" end |
#with_prefix(namespace) ⇒ Object
69 70 71 |
# File 'lib/rbs/type_name.rb', line 69 def with_prefix(namespace) self.class.new(namespace: namespace + self.namespace, name: name) end |