Class: RBS::Inline::AST::Annotations::VarType

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

Instance Attribute Summary collapse

Attributes inherited from Base

#source, #tree

Instance Method Summary collapse

Constructor Details

#initialize(tree, source) ⇒ VarType

Returns a new instance of VarType.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rbs/inline/ast/annotations.rb', line 132

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

  lvar_tree = tree.nth_tree!(1)

  # :tLVAR doesn't have `!` prefix
  # :tELVAR has `!` prefix to escape keywords
  @name = lvar_tree.nth_token!(0)[1].delete_prefix("!").to_sym

  if type = lvar_tree.nth_type?(2)
    @type = type
  end

  if comment = lvar_tree.nth_tree(3)
    @comment = comment.to_s
  end
end

Instance Attribute Details

#commentString? (readonly)

: String?

Returns:

  • (String, nil)


129
130
131
# File 'lib/rbs/inline/ast/annotations.rb', line 129

def comment
  @comment
end

#nameSymbol (readonly)

: Symbol

Returns:

  • (Symbol)


125
126
127
# File 'lib/rbs/inline/ast/annotations.rb', line 125

def name
  @name
end

#typeTypes::t? (readonly)

: Types::t?

Returns:

  • (Types::t, nil)


127
128
129
# File 'lib/rbs/inline/ast/annotations.rb', line 127

def type
  @type
end

Instance Method Details

#complete?Boolean

: () -> bool

Returns:

  • (Boolean)


152
153
154
155
156
157
158
# File 'lib/rbs/inline/ast/annotations.rb', line 152

def complete?
  if name && type
    true
  else
    false
  end
end