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
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
Returns a new instance of StringEmbExpr.
8105 8106 8107 8108 8109 |
# File 'lib/syntax_tree/node.rb', line 8105 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
8103 8104 8105 |
# File 'lib/syntax_tree/node.rb', line 8103 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be interpolated
8100 8101 8102 |
# File 'lib/syntax_tree/node.rb', line 8100 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
8111 8112 8113 |
# File 'lib/syntax_tree/node.rb', line 8111 def accept(visitor) visitor.visit_string_embexpr(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8115 8116 8117 |
# File 'lib/syntax_tree/node.rb', line 8115 def child_nodes [statements] end |
#deconstruct_keys(keys) ⇒ Object
8121 8122 8123 |
# File 'lib/syntax_tree/node.rb', line 8121 def deconstruct_keys(keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 |
# File 'lib/syntax_tree/node.rb', line 8125 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 |