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



8547
8548
8549
8550
8551
# File 'lib/syntax_tree/node.rb', line 8547

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



8545
8546
8547
# File 'lib/syntax_tree/node.rb', line 8545

def comments
  @comments
end

#variableObject (readonly)

Backref | VarRef

the variable being interpolated



8542
8543
8544
# File 'lib/syntax_tree/node.rb', line 8542

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



8553
8554
8555
# File 'lib/syntax_tree/node.rb', line 8553

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

#child_nodesObject Also known as: deconstruct



8557
8558
8559
# File 'lib/syntax_tree/node.rb', line 8557

def child_nodes
  [variable]
end

#deconstruct_keys(_keys) ⇒ Object



8563
8564
8565
# File 'lib/syntax_tree/node.rb', line 8563

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

#format(q) ⇒ Object



8567
8568
8569
8570
8571
# File 'lib/syntax_tree/node.rb', line 8567

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