Class: RubyNext::Language::Rewriters::RefinementImportMethods

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb

Constant Summary collapse

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")

Instance Attribute Summary

Attributes inherited from Base

#locals

Instance Method Summary collapse

Methods inherited from Base

ast?, #initialize, #s

Methods inherited from Abstract

ast?, #initialize, text?, transform, unsupported_syntax?, unsupported_version?

Constructor Details

This class inherits a constructor from RubyNext::Language::Rewriters::Base

Instance Method Details

#on_block(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb', line 12

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

#on_send(node) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb', line 34

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