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

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ VarRef

Returns a new instance of VarRef.



9485
9486
9487
9488
9489
# File 'lib/syntax_tree/node.rb', line 9485

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

Instance Attribute Details

#comments ⇒ Object (readonly)

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



9483
9484
9485
# File 'lib/syntax_tree/node.rb', line 9483

def comments
  @comments
end

#value ⇒ Object (readonly)

[Const | CVar | GVar | Ident | IVar | Kw] the value of this node



9480
9481
9482
# File 'lib/syntax_tree/node.rb', line 9480

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



9491
9492
9493
# File 'lib/syntax_tree/node.rb', line 9491

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

#child_nodes ⇒ Object Also known as: deconstruct



9495
9496
9497
# File 'lib/syntax_tree/node.rb', line 9495

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



9501
9502
9503
# File 'lib/syntax_tree/node.rb', line 9501

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

#format(q) ⇒ Object



9505
9506
9507
# File 'lib/syntax_tree/node.rb', line 9505

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