class SyntaxTree::StringDVar

StringDVar represents shorthand interpolation of a variable into a string. It allows you to take an instance variable, class variable, or global variable and omit the braces when interpolating.

"#@variable"

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

variable[R]
Backref | VarRef

the variable being interpolated

Public Class Methods

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

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 10234
def ===(other)
  other.is_a?(StringDVar) && variable === other.variable
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 10203
def accept(visitor)
  visitor.visit_string_dvar(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 10207
def child_nodes
  [variable]
end
Also aliased as: deconstruct
copy(variable: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 10211
def copy(variable: nil, location: nil)
  node =
    StringDVar.new(
      variable: variable || self.variable,
      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 10224
def deconstruct_keys(_keys)
  { variable: variable, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 10228
def format(q)
  q.text('#{')
  q.format(variable)
  q.text("}")
end