Class: YARP::LocalVariableTargetNode

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

Overview

Represents writing to a local variable in a context that doesn’t have an explicit value.

foo, bar = baz
^^^  ^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, depth, location) ⇒ LocalVariableTargetNode

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



6769
6770
6771
6772
6773
# File 'lib/yarp/node.rb', line 6769

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

Instance Attribute Details

#depthObject (readonly)

attr_reader depth: Integer



6766
6767
6768
# File 'lib/yarp/node.rb', line 6766

def depth
  @depth
end

#nameObject (readonly)

attr_reader name: Symbol



6763
6764
6765
# File 'lib/yarp/node.rb', line 6763

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6776
6777
6778
# File 'lib/yarp/node.rb', line 6776

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

#child_nodesObject Also known as: deconstruct

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



6781
6782
6783
# File 'lib/yarp/node.rb', line 6781

def child_nodes
  []
end

#comment_targetsObject

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



6786
6787
6788
# File 'lib/yarp/node.rb', line 6786

def comment_targets
  []
end

#copy(**params) ⇒ Object

def copy: (**params) -> LocalVariableTargetNode



6791
6792
6793
6794
6795
6796
6797
# File 'lib/yarp/node.rb', line 6791

def copy(**params)
  LocalVariableTargetNode.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]



6803
6804
6805
# File 'lib/yarp/node.rb', line 6803

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

#inspect(inspector = NodeInspector.new) ⇒ Object



6807
6808
6809
6810
6811
6812
# File 'lib/yarp/node.rb', line 6807

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