Class: SyntaxTree::Yield
Overview
Yield represents using the yield keyword with arguments.
yield value
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- Args | Paren
-
the arguments passed to the yield.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(arguments:, location:, comments: []) ⇒ Yield
constructor
A new instance of Yield.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(arguments:, location:, comments: []) ⇒ Yield
Returns a new instance of Yield.
11356 11357 11358 11359 11360 |
# File 'lib/syntax_tree/node.rb', line 11356 def initialize(arguments:, location:, comments: []) @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- Args | Paren
-
the arguments passed to the yield
11351 11352 11353 |
# File 'lib/syntax_tree/node.rb', line 11351 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11354 11355 11356 |
# File 'lib/syntax_tree/node.rb', line 11354 def comments @comments end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
11362 11363 11364 |
# File 'lib/syntax_tree/node.rb', line 11362 def child_nodes [arguments] end |
#deconstruct_keys(keys) ⇒ Object
11368 11369 11370 |
# File 'lib/syntax_tree/node.rb', line 11368 def deconstruct_keys(keys) { arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 |
# File 'lib/syntax_tree/node.rb', line 11372 def format(q) 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("") q.format(arguments) end q.breakable("") q.if_break { q.text(")") } end end end |
#pretty_print(q) ⇒ Object
11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 |
# File 'lib/syntax_tree/node.rb', line 11390 def pretty_print(q) q.group(2, "(", ")") do q.text("yield") q.breakable q.pp(arguments) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
11401 11402 11403 11404 11405 |
# File 'lib/syntax_tree/node.rb', line 11401 def to_json(*opts) { type: :yield, args: arguments, loc: location, cmts: comments }.to_json( *opts ) end |