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, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ CVar

Returns a new instance of CVar.



3997
3998
3999
4000
4001
# File 'lib/syntax_tree/node.rb', line 3997

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3995
3996
3997
# File 'lib/syntax_tree/node.rb', line 3995

def comments
  @comments
end

#valueObject (readonly)

String

the name of the class variable



3992
3993
3994
# File 'lib/syntax_tree/node.rb', line 3992

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



4032
4033
4034
# File 'lib/syntax_tree/node.rb', line 4032

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

#accept(visitor) ⇒ Object



4003
4004
4005
# File 'lib/syntax_tree/node.rb', line 4003

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

#child_nodesObject Also known as: deconstruct



4007
4008
4009
# File 'lib/syntax_tree/node.rb', line 4007

def child_nodes
  []
end

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



4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
# File 'lib/syntax_tree/node.rb', line 4011

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



4024
4025
4026
# File 'lib/syntax_tree/node.rb', line 4024

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

#format(q) ⇒ Object



4028
4029
4030
# File 'lib/syntax_tree/node.rb', line 4028

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