Class: YARP::LocalVariableWriteNode

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

Overview

Represents writing to a local variable.

foo = 1
^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, depth, name_loc, value, operator_loc, location) ⇒ LocalVariableWriteNode

def initialize: (name: Symbol, depth: Integer, name_loc: Location, value: Node, operator_loc: Location, location: Location) -> void



6836
6837
6838
6839
6840
6841
6842
6843
# File 'lib/yarp/node.rb', line 6836

def initialize(name, depth, name_loc, value, operator_loc, location)
  @name = name
  @depth = depth
  @name_loc = name_loc
  @value = value
  @operator_loc = operator_loc
  @location = location
end

Instance Attribute Details

#depthObject (readonly)

attr_reader depth: Integer



6824
6825
6826
# File 'lib/yarp/node.rb', line 6824

def depth
  @depth
end

#nameObject (readonly)

attr_reader name: Symbol



6821
6822
6823
# File 'lib/yarp/node.rb', line 6821

def name
  @name
end

#name_locObject (readonly)

attr_reader name_loc: Location



6827
6828
6829
# File 'lib/yarp/node.rb', line 6827

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



6833
6834
6835
# File 'lib/yarp/node.rb', line 6833

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



6830
6831
6832
# File 'lib/yarp/node.rb', line 6830

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6846
6847
6848
# File 'lib/yarp/node.rb', line 6846

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

#child_nodesObject Also known as: deconstruct

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



6851
6852
6853
# File 'lib/yarp/node.rb', line 6851

def child_nodes
  [value]
end

#comment_targetsObject

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



6856
6857
6858
# File 'lib/yarp/node.rb', line 6856

def comment_targets
  [name_loc, value, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> LocalVariableWriteNode



6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
# File 'lib/yarp/node.rb', line 6861

def copy(**params)
  LocalVariableWriteNode.new(
    params.fetch(:name) { name },
    params.fetch(:depth) { depth },
    params.fetch(:name_loc) { name_loc },
    params.fetch(:value) { value },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



6876
6877
6878
# File 'lib/yarp/node.rb', line 6876

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

#inspect(inspector = NodeInspector.new) ⇒ Object



6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
# File 'lib/yarp/node.rb', line 6885

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── name: #{name.inspect}\n"
  inspector << "├── depth: #{depth.inspect}\n"
  inspector << "├── name_loc: #{inspector.location(name_loc)}\n"
  inspector << "├── value:\n"
  inspector << inspector.child_node(value, "│   ")
  inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector.to_str
end

#operatorObject

def operator: () -> String



6881
6882
6883
# File 'lib/yarp/node.rb', line 6881

def operator
  operator_loc.slice
end