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
Returns a new instance of YieldNode.
12102
12103
12104
12105
12106
|
# File 'lib/syntax_tree/node.rb', line 12102
def initialize(arguments:, location:)
@arguments = arguments
@location = location
@comments = []
end
|
Instance Attribute Details
#arguments ⇒ Object
- nil | Args | Paren
-
the arguments passed to the yield
12097
12098
12099
|
# File 'lib/syntax_tree/node.rb', line 12097
def arguments
@arguments
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12100
12101
12102
|
# File 'lib/syntax_tree/node.rb', line 12100
def
@comments
end
|
Instance Method Details
#===(other) ⇒ Object
12156
12157
12158
|
# File 'lib/syntax_tree/node.rb', line 12156
def ===(other)
other.is_a?(YieldNode) && arguments === other.arguments
end
|
#accept(visitor) ⇒ Object
12108
12109
12110
|
# File 'lib/syntax_tree/node.rb', line 12108
def accept(visitor)
visitor.visit_yield(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
12112
12113
12114
|
# File 'lib/syntax_tree/node.rb', line 12112
def child_nodes
[arguments]
end
|
#copy(arguments: nil, location: nil) ⇒ Object
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
|
# File 'lib/syntax_tree/node.rb', line 12116
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
12129
12130
12131
|
# File 'lib/syntax_tree/node.rb', line 12129
def deconstruct_keys(_keys)
{ arguments: arguments, location: location, comments: }
end
|
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
|
# File 'lib/syntax_tree/node.rb', line 12133
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
|