Class: SyntaxTree::StringDVar

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

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"

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(variable:, location:, comments: []) ⇒ StringDVar

Returns a new instance of StringDVar.



8066
8067
8068
8069
8070
# File 'lib/syntax_tree/node.rb', line 8066

def initialize(variable:, location:, comments: [])
  @variable = variable
  @location = location
  @comments = comments
end

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



8064
8065
8066
# File 'lib/syntax_tree/node.rb', line 8064

def comments
  @comments
end

#variable ⇒ Object (readonly)

[Backref | VarRef] the variable being interpolated



8061
8062
8063
# File 'lib/syntax_tree/node.rb', line 8061

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



8072
8073
8074
# File 'lib/syntax_tree/node.rb', line 8072

def accept(visitor)
  visitor.visit_string_dvar(self)
end

#child_nodes ⇒ Object Also known as: deconstruct



8076
8077
8078
# File 'lib/syntax_tree/node.rb', line 8076

def child_nodes
  [variable]
end

#deconstruct_keys(keys) ⇒ Object



8082
8083
8084
# File 'lib/syntax_tree/node.rb', line 8082

def deconstruct_keys(keys)
  { variable: variable, location: location, comments: comments }
end

#format(q) ⇒ Object



8086
8087
8088
8089
8090
# File 'lib/syntax_tree/node.rb', line 8086

def format(q)
  q.text('#{')
  q.format(variable)
  q.text("}")
end