Class: SyntaxTree::VarRef

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

Overview

VarRef represents a variable reference.

true

This can be a plain local variable like the example above. It can also be a constant, a class variable, a global variable, an instance variable, a keyword (like self, nil, true, or false), or a numbered block 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(value:, location:, comments: []) ⇒ VarRef

Returns a new instance of VarRef.



9261
9262
9263
9264
9265
# File 'lib/syntax_tree/node.rb', line 9261

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9259
9260
9261
# File 'lib/syntax_tree/node.rb', line 9259

def comments
  @comments
end

#valueObject (readonly)

Const | CVar | GVar | Ident | IVar | Kw

the value of this node



9256
9257
9258
# File 'lib/syntax_tree/node.rb', line 9256

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



9267
9268
9269
# File 'lib/syntax_tree/node.rb', line 9267

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

#child_nodesObject Also known as: deconstruct



9271
9272
9273
# File 'lib/syntax_tree/node.rb', line 9271

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



9277
9278
9279
# File 'lib/syntax_tree/node.rb', line 9277

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

#format(q) ⇒ Object



9281
9282
9283
# File 'lib/syntax_tree/node.rb', line 9281

def format(q)
  q.format(value)
end