Class: Prism::LocalVariableReadNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::LocalVariableReadNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents reading a local variable. Note that this requires that a local variable of the same name has already been written to in the same scope, otherwise it is parsed as a method call.
foo
^^^
Class Method Summary collapse
-
.type ⇒ :local_variable_read_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, depth: self.depth) ⇒ LocalVariableReadNode
:call-seq: copy(**fields) -> LocalVariableReadNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#depth ⇒ Integer
:call-seq: depth -> Integer.
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, name, depth) ⇒ LocalVariableReadNode
constructor
Initialize a new LocalVariableReadNode node.
-
#inspect ⇒ String
: () -> String.
-
#name ⇒ Symbol
:call-seq: name -> Symbol.
-
#type ⇒ :local_variable_read_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, name, depth) ⇒ LocalVariableReadNode
Initialize a new LocalVariableReadNode node.
: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Integer depth) -> void
22058 22059 22060 22061 22062 22063 22064 22065 |
# File 'lib/prism/node.rb', line 22058 def initialize(source, node_id, location, flags, name, depth) @source = source @node_id = node_id @location = location @flags = flags @name = name @depth = depth end |
Class Method Details
.type ⇒ :local_variable_read_node
See Node.type.
: () -> :local_variable_read_node
22144 22145 22146 |
# File 'lib/prism/node.rb', line 22144 def self.type :local_variable_read_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
22206 22207 22208 22209 22210 |
# File 'lib/prism/node.rb', line 22206 def ===(other) # :nodoc: other.is_a?(LocalVariableReadNode) && (name === other.name) && (depth === other.depth) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
22081 22082 22083 |
# File 'lib/prism/node.rb', line 22081 def accept(visitor) visitor.visit_local_variable_read_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
22088 22089 22090 |
# File 'lib/prism/node.rb', line 22088 def child_nodes [] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
22104 22105 22106 |
# File 'lib/prism/node.rb', line 22104 def compact_child_nodes [] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, depth: self.depth) ⇒ LocalVariableReadNode
:call-seq:
copy(**fields) -> LocalVariableReadNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?depth: Integer) -> LocalVariableReadNode
22114 22115 22116 |
# File 'lib/prism/node.rb', line 22114 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, depth: self.depth) LocalVariableReadNode.new(source, node_id, location, flags, name, depth) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
22121 22122 22123 22124 22125 22126 22127 22128 22129 22130 22131 22132 |
# File 'lib/prism/node.rb', line 22121 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location name depth]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :name then deconstructed[:name] = self.name when :depth then deconstructed[:depth] = self.depth end end end |
#depth ⇒ Integer
:call-seq:
depth -> Integer
The number of visible scopes that should be searched to find the origin of this local variable.
foo = 1; foo # depth 0
bar = 2; tap { bar } # depth 1
Explore code sample The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see the Prism documentation.
: () -> Integer
22197 22198 22199 |
# File 'lib/prism/node.rb', line 22197 def depth @depth end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
22096 22097 22098 22099 |
# File 'lib/prism/node.rb', line 22096 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? end |
#inspect ⇒ String
: () -> String
22149 22150 22151 |
# File 'lib/prism/node.rb', line 22149 def inspect # :nodoc: InspectVisitor.compose(self) end |
#name ⇒ Symbol
:call-seq:
name -> Symbol
The name of the local variable, which is an identifier.
x # name `:x`
_Test # name `:_Test`
Explore code sample Note that this can also be an underscore followed by a number for the default block parameters.
_1 # name `:_1`
: () -> Symbol
22177 22178 22179 |
# File 'lib/prism/node.rb', line 22177 def name @name end |
#type ⇒ :local_variable_read_node
See Node#type.
: () -> :local_variable_read_node
22137 22138 22139 |
# File 'lib/prism/node.rb', line 22137 def type :local_variable_read_node end |