Sha256: 174f525e674d098b25fde9ec04a893c35877c9de0eb2fe254987a124653bec42

Contents?: true

Size: 857 Bytes

Versions: 16

Compression:

Stored size: 857 Bytes

Contents

# typed: strict
# frozen_string_literal: true

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

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/rbi-0.0.16/lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.16 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.15 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.14 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.13 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.12 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.11 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.10 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.9 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.8 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.7 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.6 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.5 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.4 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.3 lib/rbi/rewriters/nest_singleton_methods.rb
rbi-0.0.2 lib/rbi/rewriters/nest_singleton_methods.rb