Class: RubyNext::Language::Rewriters::AnonymousRestArgs
- Inherits:
-
Base
- Object
- Parser::TreeRewriter
- Abstract
- Base
- RubyNext::Language::Rewriters::AnonymousRestArgs
show all
- Defined in:
- lib/ruby-next/language/rewriters/3.2/anonymous_restargs.rb
Constant Summary
collapse
- NAME =
"anonymous-rest-args"
- SYNTAX_PROBE =
"obj = Object.new; def obj.foo(*) bar(*); end"
- MIN_SUPPORTED_VERSION =
Gem::Version.new("3.2.0")
- REST =
:__rest__
- KWREST =
:__kwrest__
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?
Instance Method Details
#on_args(node) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/ruby-next/language/rewriters/3.2/anonymous_restargs.rb', line 14
def on_args(node)
rest = node.children.find { |child| child.is_a?(::Parser::AST::Node) && child.type == :restarg && child.children.first.nil? }
kwrest = node.children.find { |child| child.is_a?(::Parser::AST::Node) && child.type == :kwrestarg && child.children.first.nil? }
return super unless rest || kwrest
context.track! self
replace(rest.loc.expression, "*#{REST}") if rest
replace(kwrest.loc.expression, "**#{KWREST}") if kwrest
new_args = node.children.map do |child|
if child == rest
s(:restarg, REST)
elsif child == kwrest
s(:kwrestarg, KWREST)
else
child
end
end
node.updated(:args, new_args)
end
|
#on_send(node) ⇒ Object
38
39
40
41
42
|
# File 'lib/ruby-next/language/rewriters/3.2/anonymous_restargs.rb', line 38
def on_send(node)
return super unless forwarded_args?(node)
process_send_args(node)
end
|
#on_super(node) ⇒ Object
44
45
46
47
48
|
# File 'lib/ruby-next/language/rewriters/3.2/anonymous_restargs.rb', line 44
def on_super(node)
return super unless forwarded_args?(node)
process_send_args(node)
end
|