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.



7522
7523
7524
7525
7526
# File 'lib/syntax_tree/node.rb', line 7522

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



7520
7521
7522
# File 'lib/syntax_tree/node.rb', line 7520

def comments
  @comments
end

#variableObject (readonly)

Backref | VarRef

the variable being interpolated



7517
7518
7519
# File 'lib/syntax_tree/node.rb', line 7517

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



7528
7529
7530
# File 'lib/syntax_tree/node.rb', line 7528

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

#child_nodesObject Also known as: deconstruct



7532
7533
7534
# File 'lib/syntax_tree/node.rb', line 7532

def child_nodes
  [variable]
end

#deconstruct_keys(keys) ⇒ Object



7538
7539
7540
# File 'lib/syntax_tree/node.rb', line 7538

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

#format(q) ⇒ Object



7542
7543
7544
7545
7546
# File 'lib/syntax_tree/node.rb', line 7542

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