Class: Prism::InstanceVariableReadNode

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

Overview

Represents referencing an instance variable.

@foo
^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new InstanceVariableReadNode node.



10109
10110
10111
10112
10113
10114
10115
# File 'lib/prism/node.rb', line 10109

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 instance variable, which is a ‘@` followed by an [identifier](github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).

@x     # name `:@x`

@_test # name `:@_test`


10155
10156
10157
# File 'lib/prism/node.rb', line 10155

def name
  @name
end

Class Method Details

.typeObject

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



10168
10169
10170
# File 'lib/prism/node.rb', line 10168

def self.type
  :instance_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.



10174
10175
10176
10177
# File 'lib/prism/node.rb', line 10174

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



10118
10119
10120
# File 'lib/prism/node.rb', line 10118

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

#child_nodesObject Also known as: deconstruct

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



10123
10124
10125
# File 'lib/prism/node.rb', line 10123

def child_nodes
  []
end

#comment_targetsObject

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



10133
10134
10135
# File 'lib/prism/node.rb', line 10133

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



10128
10129
10130
# File 'lib/prism/node.rb', line 10128

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) -> InstanceVariableReadNode



10138
10139
10140
# File 'lib/prism/node.rb', line 10138

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

#deconstruct_keys(keys) ⇒ Object

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



10146
10147
10148
# File 'lib/prism/node.rb', line 10146

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

#inspectObject

def inspect -> String



10158
10159
10160
# File 'lib/prism/node.rb', line 10158

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



10163
10164
10165
# File 'lib/prism/node.rb', line 10163

def type
  :instance_variable_read_node
end