Class: RBS::Inline::AST::Members::RBSIvar

Inherits:
RBSBase
  • Object
show all
Defined in:
lib/rbs/inline/ast/members.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#start_line

Constructor Details

#initialize(comment, annotation) ⇒ RBSIvar



524
525
526
527
528
529
# File 'lib/rbs/inline/ast/members.rb', line 524

def initialize(comment, annotation) #: void
  @comment = comment
  @annotation = annotation

  super(comment.comments[0].location)
end

Instance Attribute Details

#annotationObject (readonly)

: Annotations::IvarType



518
519
520
# File 'lib/rbs/inline/ast/members.rb', line 518

def annotation
  @annotation
end

#commentObject (readonly)

: AnnotationParser::ParsingResult



520
521
522
# File 'lib/rbs/inline/ast/members.rb', line 520

def comment
  @comment
end

Instance Method Details

#rbsObject

: RBS::AST::Members::InstanceVariable | RBS::AST::Members::ClassInstanceVariable | nil



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/rbs/inline/ast/members.rb', line 531

def rbs #: RBS::AST::Members::InstanceVariable | RBS::AST::Members::ClassInstanceVariable | nil
  if annotation.type
    if annotation.comment
      string = annotation.comment.delete_prefix("--").lstrip
      comment = RBS::AST::Comment.new(string: string, location: nil)
    end

    if annotation.class_instance
      RBS::AST::Members::ClassInstanceVariable.new(
        name: annotation.name,
        type: annotation.type,
        location: nil,
        comment: comment
      )
    else
      RBS::AST::Members::InstanceVariable.new(
        name: annotation.name,
        type: annotation.type,
        location: nil,
        comment: comment
      )
    end
  end
end