Class: RBI::Rewriters::Annotate

Inherits:
Visitor
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/rbi/rewriters/annotate.rb

Instance Method Summary collapse

Methods inherited from Visitor

#visit_all, #visit_file

Constructor Details

#initialize(annotation, annotate_scopes: false, annotate_properties: false) ⇒ Annotate

Returns a new instance of Annotate.



10
11
12
13
14
15
# File 'lib/rbi/rewriters/annotate.rb', line 10

def initialize(annotation, annotate_scopes: false, annotate_properties: false)
  super()
  @annotation = annotation
  @annotate_scopes = annotate_scopes
  @annotate_properties = annotate_properties
end

Instance Method Details

#visit(node) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rbi/rewriters/annotate.rb', line 18

def visit(node)
  case node
  when Scope
    annotate_node(node) if @annotate_scopes || root?(node)
  when Const, Attr, Method, TStructField, TypeMember
    annotate_node(node) if @annotate_properties
  end
  visit_all(node.nodes) if node.is_a?(Tree)
end