Class: RBS::AST::Ruby::Annotations::BlockParamTypeAnnotation

Inherits:
Base
  • Object
show all
Defined in:
lib/rbs/ast/ruby/annotations.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#location, #prefix_location

Instance Method Summary collapse

Methods inherited from Base

#buffer

Constructor Details

#initialize(location:, prefix_location:, ampersand_location:, name_location:, colon_location:, question_location:, type_location:, type:, comment_location:) ⇒ BlockParamTypeAnnotation

Returns a new instance of BlockParamTypeAnnotation.



359
360
361
362
363
364
365
366
367
368
# File 'lib/rbs/ast/ruby/annotations.rb', line 359

def initialize(location:, prefix_location:, ampersand_location:, name_location:, colon_location:, question_location:, type_location:, type:, comment_location:)
  super(location, prefix_location)
  @ampersand_location = ampersand_location
  @name_location = name_location
  @colon_location = colon_location
  @question_location = question_location
  @type_location = type_location
  @type = type
  @comment_location = comment_location
end

Instance Attribute Details

#ampersand_locationObject (readonly)

Returns the value of attribute ampersand_location.



357
358
359
# File 'lib/rbs/ast/ruby/annotations.rb', line 357

def ampersand_location
  @ampersand_location
end

#colon_locationObject (readonly)

Returns the value of attribute colon_location.



357
358
359
# File 'lib/rbs/ast/ruby/annotations.rb', line 357

def colon_location
  @colon_location
end

#comment_locationObject (readonly)

Returns the value of attribute comment_location.



357
358
359
# File 'lib/rbs/ast/ruby/annotations.rb', line 357

def comment_location
  @comment_location
end

#name_locationObject (readonly)

Returns the value of attribute name_location.



357
358
359
# File 'lib/rbs/ast/ruby/annotations.rb', line 357

def name_location
  @name_location
end

#question_locationObject (readonly)

Returns the value of attribute question_location.



357
358
359
# File 'lib/rbs/ast/ruby/annotations.rb', line 357

def question_location
  @question_location
end

#typeObject (readonly)

Returns the value of attribute type.



357
358
359
# File 'lib/rbs/ast/ruby/annotations.rb', line 357

def type
  @type
end

#type_locationObject (readonly)

Returns the value of attribute type_location.



357
358
359
# File 'lib/rbs/ast/ruby/annotations.rb', line 357

def type_location
  @type_location
end

Instance Method Details

#map_type_name(&block) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/rbs/ast/ruby/annotations.rb', line 370

def map_type_name(&block)
  self.class.new(
    location:,
    prefix_location:,
    ampersand_location: ampersand_location,
    name_location: name_location,
    colon_location: colon_location,
    question_location: question_location,
    type_location: type_location,
    type: type.map_type_name { yield _1 },
    comment_location: comment_location
  ) #: self
end

#nameObject



384
385
386
# File 'lib/rbs/ast/ruby/annotations.rb', line 384

def name
  name_location&.source&.to_sym
end

#optional?Boolean

Returns:

  • (Boolean)


388
389
390
# File 'lib/rbs/ast/ruby/annotations.rb', line 388

def optional?
  question_location ? true : false
end

#required?Boolean

Returns:

  • (Boolean)


392
393
394
# File 'lib/rbs/ast/ruby/annotations.rb', line 392

def required?
  !optional?
end

#type_fingerprintObject



396
397
398
399
400
401
402
403
404
# File 'lib/rbs/ast/ruby/annotations.rb', line 396

def type_fingerprint
  [
    "annots/block_param_type",
    name_location&.source,
    type.to_s,
    optional? ? "optional" : "required",
    comment_location&.source
  ]
end