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.
12232
12233
12234
12235
12236
|
# File 'lib/syntax_tree/node.rb', line 12232
def initialize(arguments:, location:)
@arguments = arguments
@location = location
@comments = []
end
|
Instance Attribute Details
#arguments ⇒ Object
- nil | Args | Paren
-
the arguments passed to the yield
12227
12228
12229
|
# File 'lib/syntax_tree/node.rb', line 12227
def arguments
@arguments
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12230
12231
12232
|
# File 'lib/syntax_tree/node.rb', line 12230
def
@comments
end
|
Instance Method Details
#===(other) ⇒ Object
12286
12287
12288
|
# File 'lib/syntax_tree/node.rb', line 12286
def ===(other)
other.is_a?(YieldNode) && arguments === other.arguments
end
|
#accept(visitor) ⇒ Object
12238
12239
12240
|
# File 'lib/syntax_tree/node.rb', line 12238
def accept(visitor)
visitor.visit_yield(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
12242
12243
12244
|
# File 'lib/syntax_tree/node.rb', line 12242
def child_nodes
[arguments]
end
|
#copy(arguments: nil, location: nil) ⇒ Object
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
|
# File 'lib/syntax_tree/node.rb', line 12246
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
12259
12260
12261
|
# File 'lib/syntax_tree/node.rb', line 12259
def deconstruct_keys(_keys)
{ arguments: arguments, location: location, comments: }
end
|
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
|
# File 'lib/syntax_tree/node.rb', line 12263
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
|