Class: Prism::ClassVariableReadNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents referencing a class variable.

@@foo
^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name) ⇒ ClassVariableReadNode

Initialize a new ClassVariableReadNode node.



4329
4330
4331
4332
4333
4334
4335
# File 'lib/prism/node.rb', line 4329

def initialize(source, node_id, location, flags, name)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

The name of the class variable, which is a ‘@@` followed by an [identifier](github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).

@@abc   # name `:@@abc`

@@_test # name `:@@_test`


4375
4376
4377
# File 'lib/prism/node.rb', line 4375

def name
  @name
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



4388
4389
4390
# File 'lib/prism/node.rb', line 4388

def self.type
  :class_variable_read_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



4394
4395
4396
4397
# File 'lib/prism/node.rb', line 4394

def ===(other)
  other.is_a?(ClassVariableReadNode) &&
    (name === other.name)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



4338
4339
4340
# File 'lib/prism/node.rb', line 4338

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



4343
4344
4345
# File 'lib/prism/node.rb', line 4343

def child_nodes
  []
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



4353
4354
4355
# File 'lib/prism/node.rb', line 4353

def comment_targets
  [] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



4348
4349
4350
# File 'lib/prism/node.rb', line 4348

def compact_child_nodes
  []
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> ClassVariableReadNode



4358
4359
4360
# File 'lib/prism/node.rb', line 4358

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
  ClassVariableReadNode.new(source, node_id, location, flags, name)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol }



4366
4367
4368
# File 'lib/prism/node.rb', line 4366

def deconstruct_keys(keys)
  { node_id: node_id, location: location, name: name }
end

#inspectObject

def inspect -> String



4378
4379
4380
# File 'lib/prism/node.rb', line 4378

def inspect
  InspectVisitor.compose(self)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



4383
4384
4385
# File 'lib/prism/node.rb', line 4383

def type
  :class_variable_read_node
end