Sha256: 134994e9ee60080428cf1f3c361bce2011c9f787588e7f02c4c0d5da0b3046f1

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

# Add binding argument to all self-less eval's
module RubyNext
  module Language
    module Rewriters
      class RefinementImportMethods < Language::Rewriters::Base
        NAME = "refinement-import-methods"
        SYNTAX_PROBE = "a = Module.new{}; Module.new do; refine String do; import_methods a end; end"
        MIN_SUPPORTED_VERSION = Gem::Version.new("3.1.0")

        def on_block(node)
          sender, args, body = *node
          receiver, mid, * = *sender

          return super unless mid == :refine && receiver.nil?

          return super unless body

          @within_refinement = true

          node.updated(
            nil,
            [
              sender,
              args,
              process(body)
            ]
          ).tap do
            @within_refinement = false
          end
        end

        def on_send(node)
          return super unless @within_refinement

          _receiver, mid, *children = *node

          return super unless mid == :import_methods

          context.track! self

          updated = node.updated(
            nil,
            [
              s(:const, s(:const, s(:cbase), :RubyNext), :Core),
              mid,
              *children,
              s(:send, nil, :binding)
            ]
          )

          replace(node.loc.expression, updated)

          updated
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ruby-next-core-1.1.0 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-1.0.3 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-1.0.2 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-1.0.1 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-1.0.0 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-1.0.0.rc.1 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-0.15.3 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-0.15.2 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-0.15.1 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-0.15.0 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-0.14.1 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb
ruby-next-core-0.14.0 lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb