Class: SyntaxTree::StringEmbExpr
- Inherits:
-
Object
- Object
- SyntaxTree::StringEmbExpr
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be interpolated.
Instance Method Summary collapse
- #child_nodes ⇒ 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.
11140 11141 11142 11143 11144 |
# File 'lib/syntax_tree.rb', line 11140 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
11138 11139 11140 |
# File 'lib/syntax_tree.rb', line 11138 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11135 11136 11137 |
# File 'lib/syntax_tree.rb', line 11135 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be interpolated
11132 11133 11134 |
# File 'lib/syntax_tree.rb', line 11132 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
11146 11147 11148 |
# File 'lib/syntax_tree.rb', line 11146 def child_nodes [statements] end |
#format(q) ⇒ Object
11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 |
# File 'lib/syntax_tree.rb', line 11150 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
11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 |
# File 'lib/syntax_tree.rb', line 11171 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
11182 11183 11184 11185 11186 11187 11188 11189 |
# File 'lib/syntax_tree.rb', line 11182 def to_json(*opts) { type: :string_embexpr, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |