Class: SyntaxTree::StringEmbExpr
Overview
StringEmbExpr represents interpolated content. It can be contained within a couple of different parent nodes, including regular expressions, strings, and dynamic symbols.
"string #{expression}"
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be interpolated.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
constructor
A new instance of StringEmbExpr.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
Returns a new instance of StringEmbExpr.
9326 9327 9328 9329 9330 |
# File 'lib/syntax_tree/node.rb', line 9326 def initialize(statements:, location:, comments: []) @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9324 9325 9326 |
# File 'lib/syntax_tree/node.rb', line 9324 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be interpolated
9321 9322 9323 |
# File 'lib/syntax_tree/node.rb', line 9321 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
9332 9333 9334 |
# File 'lib/syntax_tree/node.rb', line 9332 def child_nodes [statements] end |
#deconstruct_keys(keys) ⇒ Object
9338 9339 9340 |
# File 'lib/syntax_tree/node.rb', line 9338 def deconstruct_keys(keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 |
# File 'lib/syntax_tree/node.rb', line 9342 def format(q) if location.start_line == location.end_line # If the contents of this embedded expression were originally on the # same line in the source, then we're going to leave them in place and # assume that's the way the developer wanted this expression # represented. doc = q.group(0, '#{', "}") { q.format(statements) } RemoveBreaks.call(doc) else q.group do q.text('#{') q.indent do q.breakable("") q.format(statements) end q.breakable("") q.text("}") end end end |
#pretty_print(q) ⇒ Object
9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 |
# File 'lib/syntax_tree/node.rb', line 9363 def pretty_print(q) q.group(2, "(", ")") do q.text("string_embexpr") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9374 9375 9376 9377 9378 9379 9380 9381 |
# File 'lib/syntax_tree/node.rb', line 9374 def to_json(*opts) { type: :string_embexpr, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |