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, #pretty_print, #to_json
Constructor Details
#initialize(arguments:, location:) ⇒ YieldNode
12141
12142
12143
12144
12145
|
# File 'lib/syntax_tree/node.rb', line 12141
def initialize(arguments:, location:)
@arguments = arguments
@location = location
= []
end
|
Instance Attribute Details
#arguments ⇒ Object
- nil | Args | Paren
-
the arguments passed to the yield
12136
12137
12138
|
# File 'lib/syntax_tree/node.rb', line 12136
def arguments
@arguments
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12139
12140
12141
|
# File 'lib/syntax_tree/node.rb', line 12139
def
end
|
Instance Method Details
#===(other) ⇒ Object
12195
12196
12197
|
# File 'lib/syntax_tree/node.rb', line 12195
def ===(other)
other.is_a?(YieldNode) && arguments === other.arguments
end
|
#accept(visitor) ⇒ Object
12147
12148
12149
|
# File 'lib/syntax_tree/node.rb', line 12147
def accept(visitor)
visitor.visit_yield(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
12151
12152
12153
|
# File 'lib/syntax_tree/node.rb', line 12151
def child_nodes
[arguments]
end
|
#copy(arguments: nil, location: nil) ⇒ Object
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
|
# File 'lib/syntax_tree/node.rb', line 12155
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
12168
12169
12170
|
# File 'lib/syntax_tree/node.rb', line 12168
def deconstruct_keys(_keys)
{ arguments: arguments, location: location, comments: }
end
|
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
|
# File 'lib/syntax_tree/node.rb', line 12172
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
|