Class: RBS::Types::ClassInstance
- Inherits:
-
Object
- Object
- RBS::Types::ClassInstance
- Includes:
- Application, _TypeBase
- Defined in:
- sig/types.rbs,
lib/rbs/types.rb
Overview
ClassInstance represents a type of an instance of a class.
String # Type of an instance of String class.
Array[String] # Type of an instance of Array class with instances of String.
Kernel # Type of an instance of a class which includes Kernel.
Instance Attribute Summary collapse
-
#location ⇒ loc?
readonly
Returns the value of attribute location.
Attributes included from Application
Instance Method Summary collapse
-
#initialize(name:, args:, location:) ⇒ ClassInstance
constructor
A new instance of ClassInstance.
- #map_type {|arg0| ... } ⇒ Object
- #map_type_name(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(state = nil) ⇒ Object
Methods included from Application
#==, #each_type, #free_variables, #has_classish_type?, #has_self_type?, #hash, #to_s, #with_nonreturn_void?
Methods included from _TypeBase
#each_type, #free_variables, #has_classish_type?, #has_self_type?, #to_s, #with_nonreturn_void?
Constructor Details
#initialize(name:, args:, location:) ⇒ ClassInstance
Returns a new instance of ClassInstance.
371 372 373 374 375 |
# File 'lib/rbs/types.rb', line 371 def initialize(name:, args:, location:) @name = name @args = args @location = location end |
Instance Attribute Details
#location ⇒ loc? (readonly)
Returns the value of attribute location.
367 368 369 |
# File 'lib/rbs/types.rb', line 367 def location @location end |
Instance Method Details
#map_type ⇒ ClassInstance #map_type ⇒ Enumerator[t, ClassInstance]
397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/rbs/types.rb', line 397 def map_type(&block) if block ClassInstance.new( name: name, args: args.map {|type| yield type }, location: location ) else enum_for :map_type end end |
#map_type_name(&block) ⇒ Object
389 390 391 392 393 394 395 |
# File 'lib/rbs/types.rb', line 389 def map_type_name(&block) ClassInstance.new( name: yield(name, location, self), args: args.map {|type| type.map_type_name(&block) }, location: location ) end |
#sub(s) ⇒ Object
381 382 383 384 385 386 387 |
# File 'lib/rbs/types.rb', line 381 def sub(s) return self if s.empty? self.class.new(name: name, args: args.map {|ty| ty.sub(s) }, location: location) end |
#to_json(state = nil) ⇒ Object
377 378 379 |
# File 'lib/rbs/types.rb', line 377 def to_json(state = nil) { class: :class_instance, name: name, args: args, location: location }.to_json(state) end |