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

Returns a new instance of RBSIvar.



521
522
523
524
525
526
# File 'lib/rbs/inline/ast/members.rb', line 521

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

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

Instance Attribute Details

#annotationObject (readonly)

: Annotations::IvarType



515
516
517
# File 'lib/rbs/inline/ast/members.rb', line 515

def annotation
  @annotation
end

#commentObject (readonly)

: AnnotationParser::ParsingResult



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

def comment
  @comment
end

Instance Method Details

#rbsObject

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



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

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