Class: SyntaxTree::YieldNode
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::YieldNode
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Yield represents using the yield keyword with arguments.
yield value
Instance Attribute Summary collapse
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(arguments:, location:) ⇒ YieldNode
Returns a new instance of YieldNode.
12299
12300
12301
12302
12303
|
# File 'lib/syntax_tree/node.rb', line 12299
def initialize(arguments:, location:)
@arguments = arguments
@location = location
@comments = []
end
|
Instance Attribute Details
#arguments ⇒ Object
- nil | Args | Paren
-
the arguments passed to the yield
12294
12295
12296
|
# File 'lib/syntax_tree/node.rb', line 12294
def arguments
@arguments
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12297
12298
12299
|
# File 'lib/syntax_tree/node.rb', line 12297
def
@comments
end
|
Instance Method Details
#===(other) ⇒ Object
12353
12354
12355
|
# File 'lib/syntax_tree/node.rb', line 12353
def ===(other)
other.is_a?(YieldNode) && arguments === other.arguments
end
|
#accept(visitor) ⇒ Object
12305
12306
12307
|
# File 'lib/syntax_tree/node.rb', line 12305
def accept(visitor)
visitor.visit_yield(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
12309
12310
12311
|
# File 'lib/syntax_tree/node.rb', line 12309
def child_nodes
[arguments]
end
|
#copy(arguments: nil, location: nil) ⇒ Object
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
|
# File 'lib/syntax_tree/node.rb', line 12313
def copy(arguments: nil, location: nil)
node =
YieldNode.new(
arguments: arguments || self.arguments,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
12326
12327
12328
|
# File 'lib/syntax_tree/node.rb', line 12326
def deconstruct_keys(_keys)
{ arguments: arguments, location: location, comments: }
end
|
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
|
# File 'lib/syntax_tree/node.rb', line 12330
def format(q)
if arguments.nil?
q.text("yield")
return
end
q.group do
q.text("yield")
if arguments.is_a?(Paren)
q.format(arguments)
else
q.if_break { q.text("(") }.if_flat { q.text(" ") }
q.indent do
q.breakable_empty
q.format(arguments)
end
q.breakable_empty
q.if_break { q.text(")") }
end
end
end
|