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.
7532
7533
7534
7535
7536
7537
|
# File 'lib/syntax_tree/node.rb', line 7532
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
7527
7528
7529
|
# File 'lib/syntax_tree/node.rb', line 7527
def block
@block
end
|
#call ⇒ Object
- ARef | CallNode | Command | CommandCall | Super | ZSuper
-
the method call
7524
7525
7526
|
# File 'lib/syntax_tree/node.rb', line 7524
def call
@call
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7530
7531
7532
|
# File 'lib/syntax_tree/node.rb', line 7530
def
end
|
Instance Method Details
#===(other) ⇒ Object
7581
7582
7583
7584
|
# File 'lib/syntax_tree/node.rb', line 7581
def ===(other)
other.is_a?(MethodAddBlock) && call === other.call &&
block === other.block
end
|
#accept(visitor) ⇒ Object
7539
7540
7541
|
# File 'lib/syntax_tree/node.rb', line 7539
def accept(visitor)
visitor.visit_method_add_block(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7543
7544
7545
|
# File 'lib/syntax_tree/node.rb', line 7543
def child_nodes
[call, block]
end
|
#copy(call: nil, block: nil, location: nil) ⇒ Object
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
|
# File 'lib/syntax_tree/node.rb', line 7547
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
7561
7562
7563
|
# File 'lib/syntax_tree/node.rb', line 7561
def deconstruct_keys(_keys)
{ call: call, block: block, location: location, comments: }
end
|
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
|
# File 'lib/syntax_tree/node.rb', line 7565
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
7586
7587
7588
7589
|
# File 'lib/syntax_tree/node.rb', line 7586
def format_contents(q)
q.format(call)
q.format(block)
end
|