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.
12263
12264
12265
12266
12267
|
# File 'lib/syntax_tree/node.rb', line 12263
def initialize(arguments:, location:)
@arguments = arguments
@location = location
@comments = []
end
|
Instance Attribute Details
#arguments ⇒ Object
- nil | Args | Paren
-
the arguments passed to the yield
12258
12259
12260
|
# File 'lib/syntax_tree/node.rb', line 12258
def arguments
@arguments
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12261
12262
12263
|
# File 'lib/syntax_tree/node.rb', line 12261
def
@comments
end
|
Instance Method Details
#===(other) ⇒ Object
12317
12318
12319
|
# File 'lib/syntax_tree/node.rb', line 12317
def ===(other)
other.is_a?(YieldNode) && arguments === other.arguments
end
|
#accept(visitor) ⇒ Object
12269
12270
12271
|
# File 'lib/syntax_tree/node.rb', line 12269
def accept(visitor)
visitor.visit_yield(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
12273
12274
12275
|
# File 'lib/syntax_tree/node.rb', line 12273
def child_nodes
[arguments]
end
|
#copy(arguments: nil, location: nil) ⇒ Object
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
|
# File 'lib/syntax_tree/node.rb', line 12277
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
12290
12291
12292
|
# File 'lib/syntax_tree/node.rb', line 12290
def deconstruct_keys(_keys)
{ arguments: arguments, location: location, comments: }
end
|
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
|
# File 'lib/syntax_tree/node.rb', line 12294
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
|