class SyntaxTree::StringEmbExpr

StringEmbExpr represents interpolated content. It can be contained within a couple of different parent nodes, including regular expressions, strings, and dynamic symbols.

"string #{expression}"

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

statements[R]
Statements

the expressions to be interpolated

Public Class Methods

new(statements:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 10252
def initialize(statements:, location:)
  @statements = statements
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 10309
def ===(other)
  other.is_a?(StringEmbExpr) && statements === other.statements
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 10258
def accept(visitor)
  visitor.visit_string_embexpr(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 10262
def child_nodes
  [statements]
end
Also aliased as: deconstruct
copy(statements: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 10266
def copy(statements: nil, location: nil)
  node =
    StringEmbExpr.new(
      statements: statements || self.statements,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 10279
def deconstruct_keys(_keys)
  { statements: statements, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 10283
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 do
        q.text('#{')
        q.format(statements)
        q.text("}")
      end
    )
  else
    q.group do
      q.text('#{')
      q.indent do
        q.breakable_empty
        q.format(statements)
      end
      q.breakable_empty
      q.text("}")
    end
  end
end