Class: RBS::Inline::AST::Annotations::Generic

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/rbs/inline/ast/annotations.rb,
sig/generated/rbs/inline/ast/annotations.rbs

Overview

# @rbs generic [type param]

# @rbs generic X
# @rbs generic in Y
# @rbs generic unchecked out Z < String -- Comment here

Instance Attribute Summary collapse

Attributes inherited from Base

#source, #tree

Instance Method Summary collapse

Methods included from Utils

#translate_super_class, #translate_type_name, #translate_type_param

Constructor Details

#initialize(tree, source) ⇒ Generic

Returns a new instance of Generic.



572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/rbs/inline/ast/annotations.rb', line 572

def initialize(tree, source)
  @tree = tree
  @source = source

  generic_tree = tree.nth_tree!(1)

  @type_param = translate_type_param(generic_tree.nth_tree!(1))

  if comment = generic_tree.nth_tree?(2)
    @comment = comment.to_s
  end
end

Instance Attribute Details

#commentString? (readonly)

: String?

Returns:

  • (String, nil)


567
568
569
# File 'lib/rbs/inline/ast/annotations.rb', line 567

def comment
  @comment
end

#type_paramRBS::AST::TypeParam? (readonly)

TypeParam object or nil if syntax error

Returns:

  • (RBS::AST::TypeParam, nil)


565
566
567
# File 'lib/rbs/inline/ast/annotations.rb', line 565

def type_param
  @type_param
end