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.
12280
12281
12282
12283
12284
|
# File 'lib/syntax_tree/node.rb', line 12280
def initialize(arguments:, location:)
@arguments = arguments
@location = location
@comments = []
end
|
Instance Attribute Details
#arguments ⇒ Object
- nil | Args | Paren
-
the arguments passed to the yield
12275
12276
12277
|
# File 'lib/syntax_tree/node.rb', line 12275
def arguments
@arguments
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12278
12279
12280
|
# File 'lib/syntax_tree/node.rb', line 12278
def
@comments
end
|
Instance Method Details
#===(other) ⇒ Object
12334
12335
12336
|
# File 'lib/syntax_tree/node.rb', line 12334
def ===(other)
other.is_a?(YieldNode) && arguments === other.arguments
end
|
#accept(visitor) ⇒ Object
12286
12287
12288
|
# File 'lib/syntax_tree/node.rb', line 12286
def accept(visitor)
visitor.visit_yield(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
12290
12291
12292
|
# File 'lib/syntax_tree/node.rb', line 12290
def child_nodes
[arguments]
end
|
#copy(arguments: nil, location: nil) ⇒ Object
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
|
# File 'lib/syntax_tree/node.rb', line 12294
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
12307
12308
12309
|
# File 'lib/syntax_tree/node.rb', line 12307
def deconstruct_keys(_keys)
{ arguments: arguments, location: location, comments: }
end
|
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
|
# File 'lib/syntax_tree/node.rb', line 12311
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
|