Sha256: 647fb6fb1a1d3418e90fa7bf7bbbe597c6549f930cca07720dc1907b52d03ffe

Contents?: true

Size: 938 Bytes

Versions: 6

Compression:

Stored size: 938 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module Tapioca
  module RBI
    module Rewriters
      class NestSingletonMethods < Visitor
        extend T::Sig

        sig { override.params(node: T.nilable(Node)).void }
        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
      end
    end

    class Tree
      extend T::Sig

      sig { void }
      def nest_singleton_methods!
        visitor = Rewriters::NestSingletonMethods.new
        visitor.visit(self)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tapioca-0.4.27 lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
tapioca-0.4.26 lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
tapioca-0.4.25 lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
tapioca-0.4.24 lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
tapioca-0.4.23 lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
tapioca-0.4.22 lib/tapioca/rbi/rewriters/nest_singleton_methods.rb