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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of StringDVar.



8336
8337
8338
8339
8340
# File 'lib/syntax_tree/node.rb', line 8336

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8334
8335
8336
# File 'lib/syntax_tree/node.rb', line 8334

def comments
  @comments
end

#variableObject (readonly)

Backref | VarRef

the variable being interpolated



8331
8332
8333
# File 'lib/syntax_tree/node.rb', line 8331

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



8342
8343
8344
# File 'lib/syntax_tree/node.rb', line 8342

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

#child_nodesObject Also known as: deconstruct



8346
8347
8348
# File 'lib/syntax_tree/node.rb', line 8346

def child_nodes
  [variable]
end

#deconstruct_keys(_keys) ⇒ Object



8352
8353
8354
# File 'lib/syntax_tree/node.rb', line 8352

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

#format(q) ⇒ Object



8356
8357
8358
8359
8360
# File 'lib/syntax_tree/node.rb', line 8356

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