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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5583
5584
5585
# File 'lib/syntax_tree/node.rb', line 5583

def comments
  @comments
end

#valueObject (readonly)

String

the name of the global variable



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5620
5621
5622
# File 'lib/syntax_tree/node.rb', line 5620

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

#accept(visitor) ⇒ Object



5591
5592
5593
# File 'lib/syntax_tree/node.rb', line 5591

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

#child_nodesObject Also known as: deconstruct



5595
5596
5597
# File 'lib/syntax_tree/node.rb', line 5595

def child_nodes
  []
end

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



5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
# File 'lib/syntax_tree/node.rb', line 5599

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



5612
5613
5614
# File 'lib/syntax_tree/node.rb', line 5612

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

#format(q) ⇒ Object



5616
5617
5618
# File 'lib/syntax_tree/node.rb', line 5616

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