Class: YARP::LocalVariableReadNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/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
^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, depth, location) ⇒ LocalVariableReadNode

def initialize: (name: Symbol, depth: Integer, location: Location) -> void



6711
6712
6713
6714
6715
# File 'lib/yarp/node.rb', line 6711

def initialize(name, depth, location)
  @name = name
  @depth = depth
  @location = location
end

Instance Attribute Details

#depthObject (readonly)

attr_reader depth: Integer



6708
6709
6710
# File 'lib/yarp/node.rb', line 6708

def depth
  @depth
end

#nameObject (readonly)

attr_reader name: Symbol



6705
6706
6707
# File 'lib/yarp/node.rb', line 6705

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6718
6719
6720
# File 'lib/yarp/node.rb', line 6718

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

#child_nodesObject Also known as: deconstruct

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



6723
6724
6725
# File 'lib/yarp/node.rb', line 6723

def child_nodes
  []
end

#comment_targetsObject

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



6728
6729
6730
# File 'lib/yarp/node.rb', line 6728

def comment_targets
  []
end

#copy(**params) ⇒ Object

def copy: (**params) -> LocalVariableReadNode



6733
6734
6735
6736
6737
6738
6739
# File 'lib/yarp/node.rb', line 6733

def copy(**params)
  LocalVariableReadNode.new(
    params.fetch(:name) { name },
    params.fetch(:depth) { depth },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



6745
6746
6747
# File 'lib/yarp/node.rb', line 6745

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

#inspect(inspector = NodeInspector.new) ⇒ Object



6749
6750
6751
6752
6753
6754
# File 'lib/yarp/node.rb', line 6749

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── name: #{name.inspect}\n"
  inspector << "└── depth: #{depth.inspect}\n"
  inspector.to_str
end