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
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
constructor
A new instance of StringEmbExpr.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
Returns a new instance of StringEmbExpr.
8288 8289 8290 8291 8292 |
# File 'lib/syntax_tree/node.rb', line 8288 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
8286 8287 8288 |
# File 'lib/syntax_tree/node.rb', line 8286 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be interpolated
8283 8284 8285 |
# File 'lib/syntax_tree/node.rb', line 8283 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
8294 8295 8296 |
# File 'lib/syntax_tree/node.rb', line 8294 def accept(visitor) visitor.visit_string_embexpr(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8298 8299 8300 |
# File 'lib/syntax_tree/node.rb', line 8298 def child_nodes [statements] end |
#deconstruct_keys(_keys) ⇒ Object
8304 8305 8306 |
# File 'lib/syntax_tree/node.rb', line 8304 def deconstruct_keys(_keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 |
# File 'lib/syntax_tree/node.rb', line 8308 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 |