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

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

Overview

@rbs &name: TYPE -- comment annotation in leading comments

^^^^                               -- prefix_location
     ^                             -- ampersand_location
      ^^^^^                        -- name_location
           ^                       -- colon_location
             ^^^^^^^^^^            -- type_location
                        ^^^^^^^^^^ -- comment_location
^^^^                 -- prefix_location
     ^               -- ampersand_location
      ^              -- colon_location
        ^            -- question_location
          ^^^^^^^^^^ -- type_location

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_locationLocation (readonly)

Returns the value of attribute ampersand_location.

Returns:



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

def ampersand_location
  @ampersand_location
end

#colon_locationLocation (readonly)

Returns the value of attribute colon_location.

Returns:



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

def colon_location
  @colon_location
end

#comment_locationLocation? (readonly)

Returns the value of attribute comment_location.

Returns:



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

def comment_location
  @comment_location
end

#name_locationLocation? (readonly)

Returns the value of attribute name_location.

Returns:



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

def name_location
  @name_location
end

#question_locationLocation? (readonly)

Returns the value of attribute question_location.

Returns:



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

def question_location
  @question_location
end

#typeTypes::function (readonly)

Returns the value of attribute type.

Returns:

  • (Types::function)


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

def type
  @type
end

#type_locationLocation (readonly)

Returns the value of attribute type_location.

Returns:



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

def type_location
  @type_location
end

Instance Method Details

#map_type_name {|arg0| ... } ⇒ self

Yields:

Yield Parameters:

Yield Returns:

Returns:

  • (self)


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

Returns:

  • (Object)


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