Class: RubyNext::Language::Rewriters::AnonymousBlock
- Inherits:
-
Base
- Object
- Parser::TreeRewriter
- Abstract
- Base
- RubyNext::Language::Rewriters::AnonymousBlock
show all
- Defined in:
- lib/ruby-next/language/rewriters/3.1/anonymous_block.rb
Constant Summary
collapse
- NAME =
"anonymous-block"
- SYNTAX_PROBE =
"obj = Object.new; def obj.foo(&) bar(&); end"
- MIN_SUPPORTED_VERSION =
Gem::Version.new("3.1.0")
- BLOCK =
:__block__
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?, unsupported_syntax?, unsupported_version?
Instance Method Details
#on_args(node) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/ruby-next/language/rewriters/3.1/anonymous_block.rb', line 13
def on_args(node)
block = node.children.last
return super unless block&.type == :blockarg
return super unless block.children.first.nil?
context.track! self
replace(block.loc.expression, "&#{BLOCK}")
node.updated(
:args,
[
*node.children.slice(0, node.children.index(block)),
s(:blockarg, BLOCK)
]
)
end
|
#on_send(node) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/ruby-next/language/rewriters/3.1/anonymous_block.rb', line 32
def on_send(node)
block = (node)
return super unless block&.children == [nil]
process_block(node, block)
end
|
#on_super(node) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/ruby-next/language/rewriters/3.1/anonymous_block.rb', line 39
def on_super(node)
block = (node)
return super unless block&.children == [nil]
process_block(node, block)
end
|