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

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

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.



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

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

#commentObject (readonly)

: String?



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

def comment
  @comment
end

#nameObject (readonly)

: Symbol



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

def name
  @name
end

#typeObject (readonly)

: Types::t?



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

def type
  @type
end

Instance Method Details

#complete?Boolean

: () -> bool

Returns:

  • (Boolean)


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

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