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.



401
402
403
404
405
406
407
408
409
410
# File 'lib/rbs/ast/ruby/annotations.rb', line 401

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.



399
400
401
# File 'lib/rbs/ast/ruby/annotations.rb', line 399

def ampersand_location
  @ampersand_location
end

#colon_locationObject (readonly)

Returns the value of attribute colon_location.



399
400
401
# File 'lib/rbs/ast/ruby/annotations.rb', line 399

def colon_location
  @colon_location
end

#comment_locationObject (readonly)

Returns the value of attribute comment_location.



399
400
401
# File 'lib/rbs/ast/ruby/annotations.rb', line 399

def comment_location
  @comment_location
end

#name_locationObject (readonly)

Returns the value of attribute name_location.



399
400
401
# File 'lib/rbs/ast/ruby/annotations.rb', line 399

def name_location
  @name_location
end

#question_locationObject (readonly)

Returns the value of attribute question_location.



399
400
401
# File 'lib/rbs/ast/ruby/annotations.rb', line 399

def question_location
  @question_location
end

#typeObject (readonly)

Returns the value of attribute type.



399
400
401
# File 'lib/rbs/ast/ruby/annotations.rb', line 399

def type
  @type
end

#type_locationObject (readonly)

Returns the value of attribute type_location.



399
400
401
# File 'lib/rbs/ast/ruby/annotations.rb', line 399

def type_location
  @type_location
end

Instance Method Details

#map_type_name(&block) ⇒ Object



412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/rbs/ast/ruby/annotations.rb', line 412

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



426
427
428
# File 'lib/rbs/ast/ruby/annotations.rb', line 426

def name
  name_location&.source&.to_sym
end

#optional?Boolean

Returns:

  • (Boolean)


430
431
432
# File 'lib/rbs/ast/ruby/annotations.rb', line 430

def optional?
  question_location ? true : false
end

#required?Boolean

Returns:

  • (Boolean)


434
435
436
# File 'lib/rbs/ast/ruby/annotations.rb', line 434

def required?
  !optional?
end

#type_fingerprintObject



438
439
440
441
442
443
444
445
446
# File 'lib/rbs/ast/ruby/annotations.rb', line 438

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