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.



9374
9375
9376
9377
9378
# File 'lib/syntax_tree/node.rb', line 9374

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



9372
9373
9374
# File 'lib/syntax_tree/node.rb', line 9372

def comments
  @comments
end

#valueObject (readonly)

Const | CVar | GVar | Ident | IVar | Kw

the value of this node



9369
9370
9371
# File 'lib/syntax_tree/node.rb', line 9369

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



9380
9381
9382
# File 'lib/syntax_tree/node.rb', line 9380

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

#child_nodesObject Also known as: deconstruct



9384
9385
9386
# File 'lib/syntax_tree/node.rb', line 9384

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



9390
9391
9392
# File 'lib/syntax_tree/node.rb', line 9390

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

#format(q) ⇒ Object



9394
9395
9396
# File 'lib/syntax_tree/node.rb', line 9394

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