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.



10848
10849
10850
10851
10852
10853
10854
# File 'lib/prism/node.rb', line 10848

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`


10900
10901
10902
# File 'lib/prism/node.rb', line 10900

def name
  @name
end

Class Method Details

.typeObject

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



10913
10914
10915
# File 'lib/prism/node.rb', line 10913

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.



10919
10920
10921
10922
# File 'lib/prism/node.rb', line 10919

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



10857
10858
10859
# File 'lib/prism/node.rb', line 10857

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



10862
10863
10864
# File 'lib/prism/node.rb', line 10862

def child_nodes
  []
end

#comment_targetsObject

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



10878
10879
10880
# File 'lib/prism/node.rb', line 10878

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



10873
10874
10875
# File 'lib/prism/node.rb', line 10873

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



10883
10884
10885
# File 'lib/prism/node.rb', line 10883

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 }



10891
10892
10893
# File 'lib/prism/node.rb', line 10891

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

#each_child_nodeObject

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator



10867
10868
10869
10870
# File 'lib/prism/node.rb', line 10867

def each_child_node
  return to_enum(:each_child_node) unless block_given?

end

#inspectObject

def inspect -> String



10903
10904
10905
# File 'lib/prism/node.rb', line 10903

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



10908
10909
10910
# File 'lib/prism/node.rb', line 10908

def type
  :instance_variable_read_node
end