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.
8212 8213 8214 8215 8216 |
# File 'lib/syntax_tree/node.rb', line 8212 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
8210 8211 8212 |
# File 'lib/syntax_tree/node.rb', line 8210 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be interpolated
8207 8208 8209 |
# File 'lib/syntax_tree/node.rb', line 8207 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
8218 8219 8220 |
# File 'lib/syntax_tree/node.rb', line 8218 def accept(visitor) visitor.visit_string_embexpr(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8222 8223 8224 |
# File 'lib/syntax_tree/node.rb', line 8222 def child_nodes [statements] end |
#deconstruct_keys(_keys) ⇒ Object
8228 8229 8230 |
# File 'lib/syntax_tree/node.rb', line 8228 def deconstruct_keys(_keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 |
# File 'lib/syntax_tree/node.rb', line 8232 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. q.remove_breaks(q.group(0, '#{', "}") { q.format(statements) }) else q.group do q.text('#{') q.indent do q.breakable("") q.format(statements) end q.breakable("") q.text("}") end end end |