Class: SyntaxTree::MethodAddBlock
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::MethodAddBlock
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
MethodAddBlock represents a method call with a block argument.
method {}
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
- BlockNode
-
the block being sent with the method call.
-
#call ⇒ Object
readonly
- ARef | CallNode | Command | CommandCall | Super | ZSuper
-
the method call.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(call:, block:, location:) ⇒ MethodAddBlock
Returns a new instance of MethodAddBlock.
7563
7564
7565
7566
7567
7568
|
# File 'lib/syntax_tree/node.rb', line 7563
def initialize(call:, block:, location:)
@call = call
@block = block
@location = location
= []
end
|
Instance Attribute Details
#block ⇒ Object
- BlockNode
-
the block being sent with the method call
7558
7559
7560
|
# File 'lib/syntax_tree/node.rb', line 7558
def block
@block
end
|
#call ⇒ Object
- ARef | CallNode | Command | CommandCall | Super | ZSuper
-
the method call
7555
7556
7557
|
# File 'lib/syntax_tree/node.rb', line 7555
def call
@call
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7561
7562
7563
|
# File 'lib/syntax_tree/node.rb', line 7561
def
end
|
Instance Method Details
#===(other) ⇒ Object
7612
7613
7614
7615
|
# File 'lib/syntax_tree/node.rb', line 7612
def ===(other)
other.is_a?(MethodAddBlock) && call === other.call &&
block === other.block
end
|
#accept(visitor) ⇒ Object
7570
7571
7572
|
# File 'lib/syntax_tree/node.rb', line 7570
def accept(visitor)
visitor.visit_method_add_block(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7574
7575
7576
|
# File 'lib/syntax_tree/node.rb', line 7574
def child_nodes
[call, block]
end
|
#copy(call: nil, block: nil, location: nil) ⇒ Object
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
|
# File 'lib/syntax_tree/node.rb', line 7578
def copy(call: nil, block: nil, location: nil)
node =
MethodAddBlock.new(
call: call || self.call,
block: block || self.block,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
7592
7593
7594
|
# File 'lib/syntax_tree/node.rb', line 7592
def deconstruct_keys(_keys)
{ call: call, block: block, location: location, comments: }
end
|
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
|
# File 'lib/syntax_tree/node.rb', line 7596
def format(q)
if CallChainFormatter.chained?(call) &&
!CallChainFormatter.chained?(q.parent)
q.group do
q
.if_break { CallChainFormatter.new(self).format(q) }
.if_flat { format_contents(q) }
end
else
format_contents(q)
end
end
|
#format_contents(q) ⇒ Object
7617
7618
7619
7620
|
# File 'lib/syntax_tree/node.rb', line 7617
def format_contents(q)
q.format(call)
q.format(block)
end
|