Class: SyntaxTree::GVar

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

Overview

GVar represents a global variable literal.

$variable

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ GVar

Returns a new instance of GVar.



5554
5555
5556
5557
5558
# File 'lib/syntax_tree/node.rb', line 5554

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5552
5553
5554
# File 'lib/syntax_tree/node.rb', line 5552

def comments
  @comments
end

#valueObject (readonly)

String

the name of the global variable



5549
5550
5551
# File 'lib/syntax_tree/node.rb', line 5549

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5589
5590
5591
# File 'lib/syntax_tree/node.rb', line 5589

def ===(other)
  other.is_a?(GVar) && value === other.value
end

#accept(visitor) ⇒ Object



5560
5561
5562
# File 'lib/syntax_tree/node.rb', line 5560

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

#child_nodesObject Also known as: deconstruct



5564
5565
5566
# File 'lib/syntax_tree/node.rb', line 5564

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
# File 'lib/syntax_tree/node.rb', line 5568

def copy(value: nil, location: nil)
  node =
    GVar.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



5581
5582
5583
# File 'lib/syntax_tree/node.rb', line 5581

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

#format(q) ⇒ Object



5585
5586
5587
# File 'lib/syntax_tree/node.rb', line 5585

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