Class: RBI::Rewriters::GroupNodes

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

Instance Method Summary collapse

Methods inherited from Visitor

#visit_all, #visit_file

Instance Method Details

#visit(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rbi/rewriters/group_nodes.rb', line 12

def visit(node)
  return unless node

  case node
  when Tree
    kinds = node.nodes.map { |child| group_kind(child) }
    kinds.uniq!

    groups = {}
    kinds.each { |kind| groups[kind] = Group.new(kind) }

    node.nodes.dup.each do |child|
      visit(child)
      child.detach
      groups[group_kind(child)] << child
    end

    groups.each { |_, group| node << group }
  end
end