Class: RBI::Rewriters::NestSingletonMethods

Inherits:
Visitor
  • Object
show all
Defined in:
lib/rbi/rewriters/nest_singleton_methods.rb

Instance Method Summary collapse

Methods inherited from Visitor

#visit_all, #visit_file

Instance Method Details

#visit(node) ⇒ Object

: (Node? node) -> void



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rbi/rewriters/nest_singleton_methods.rb', line 9

def visit(node)
  return unless node

  case node
  when Tree
    singleton_class = SingletonClass.new

    node.nodes.dup.each do |child|
      visit(child)
      next unless child.is_a?(Method) && child.is_singleton

      child.detach
      child.is_singleton = false
      singleton_class << child
    end

    node << singleton_class unless singleton_class.empty?
  end
end