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
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(call:, block:, location:) ⇒ MethodAddBlock
Returns a new instance of MethodAddBlock.
7469
7470
7471
7472
7473
7474
|
# File 'lib/syntax_tree/node.rb', line 7469
def initialize(call:, block:, location:)
@call = call
@block = block
@location = location
= []
end
|
Instance Attribute Details
#block ⇒ Object
- Block
-
the block being sent with the method call
7464
7465
7466
|
# File 'lib/syntax_tree/node.rb', line 7464
def block
@block
end
|
#call ⇒ Object
- Call | Command | CommandCall
-
the method call
7461
7462
7463
|
# File 'lib/syntax_tree/node.rb', line 7461
def call
@call
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7467
7468
7469
|
# File 'lib/syntax_tree/node.rb', line 7467
def
end
|
Instance Method Details
#===(other) ⇒ Object
7518
7519
7520
7521
|
# File 'lib/syntax_tree/node.rb', line 7518
def ===(other)
other.is_a?(MethodAddBlock) && call === other.call &&
block === other.block
end
|
#accept(visitor) ⇒ Object
7476
7477
7478
|
# File 'lib/syntax_tree/node.rb', line 7476
def accept(visitor)
visitor.visit_method_add_block(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7480
7481
7482
|
# File 'lib/syntax_tree/node.rb', line 7480
def child_nodes
[call, block]
end
|
#copy(call: nil, block: nil, location: nil) ⇒ Object
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
|
# File 'lib/syntax_tree/node.rb', line 7484
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
7498
7499
7500
|
# File 'lib/syntax_tree/node.rb', line 7498
def deconstruct_keys(_keys)
{ call: call, block: block, location: location, comments: }
end
|
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
|
# File 'lib/syntax_tree/node.rb', line 7502
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
7523
7524
7525
7526
|
# File 'lib/syntax_tree/node.rb', line 7523
def format_contents(q)
q.format(call)
q.format(block)
end
|