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.



3688
3689
3690
3691
3692
3693
3694
# File 'lib/prism/node.rb', line 3688

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`


3734
3735
3736
# File 'lib/prism/node.rb', line 3734

def name
  @name
end

Class Method Details

.typeObject

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



3747
3748
3749
# File 'lib/prism/node.rb', line 3747

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.



3753
3754
3755
3756
# File 'lib/prism/node.rb', line 3753

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



3697
3698
3699
# File 'lib/prism/node.rb', line 3697

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

#child_nodesObject Also known as: deconstruct

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



3702
3703
3704
# File 'lib/prism/node.rb', line 3702

def child_nodes
  []
end

#comment_targetsObject

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



3712
3713
3714
# File 'lib/prism/node.rb', line 3712

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



3707
3708
3709
# File 'lib/prism/node.rb', line 3707

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



3717
3718
3719
# File 'lib/prism/node.rb', line 3717

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 }



3725
3726
3727
# File 'lib/prism/node.rb', line 3725

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

#inspectObject

def inspect -> String



3737
3738
3739
# File 'lib/prism/node.rb', line 3737

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



3742
3743
3744
# File 'lib/prism/node.rb', line 3742

def type
  :class_variable_read_node
end