Class: SyntaxTree::CVar

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

Overview

CVar represents the use of a class variable.

@@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:) ⇒ CVar

Returns a new instance of CVar.



4053
4054
4055
4056
4057
# File 'lib/syntax_tree/node.rb', line 4053

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4051
4052
4053
# File 'lib/syntax_tree/node.rb', line 4051

def comments
  @comments
end

#valueObject (readonly)

String

the name of the class variable



4048
4049
4050
# File 'lib/syntax_tree/node.rb', line 4048

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



4088
4089
4090
# File 'lib/syntax_tree/node.rb', line 4088

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

#accept(visitor) ⇒ Object



4059
4060
4061
# File 'lib/syntax_tree/node.rb', line 4059

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

#child_nodesObject Also known as: deconstruct



4063
4064
4065
# File 'lib/syntax_tree/node.rb', line 4063

def child_nodes
  []
end

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



4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
# File 'lib/syntax_tree/node.rb', line 4067

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

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

#deconstruct_keys(_keys) ⇒ Object



4080
4081
4082
# File 'lib/syntax_tree/node.rb', line 4080

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

#format(q) ⇒ Object



4084
4085
4086
# File 'lib/syntax_tree/node.rb', line 4084

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