Class: YARP::InstanceVariableWriteNode

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

Overview

Represents writing to an instance variable.

@foo = 1
^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, name_loc, value, operator_loc, location) ⇒ InstanceVariableWriteNode

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



5681
5682
5683
5684
5685
5686
5687
# File 'lib/yarp/node.rb', line 5681

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol



5669
5670
5671
# File 'lib/yarp/node.rb', line 5669

def name
  @name
end

#name_locObject (readonly)

attr_reader name_loc: Location



5672
5673
5674
# File 'lib/yarp/node.rb', line 5672

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



5678
5679
5680
# File 'lib/yarp/node.rb', line 5678

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



5675
5676
5677
# File 'lib/yarp/node.rb', line 5675

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



5690
5691
5692
# File 'lib/yarp/node.rb', line 5690

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

#child_nodesObject Also known as: deconstruct

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



5695
5696
5697
# File 'lib/yarp/node.rb', line 5695

def child_nodes
  [value]
end

#comment_targetsObject

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



5700
5701
5702
# File 'lib/yarp/node.rb', line 5700

def comment_targets
  [name_loc, value, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> InstanceVariableWriteNode



5705
5706
5707
5708
5709
5710
5711
5712
5713
# File 'lib/yarp/node.rb', line 5705

def copy(**params)
  InstanceVariableWriteNode.new(
    params.fetch(:name) { name },
    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]



5719
5720
5721
# File 'lib/yarp/node.rb', line 5719

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

#inspect(inspector = NodeInspector.new) ⇒ Object



5728
5729
5730
5731
5732
5733
5734
5735
5736
# File 'lib/yarp/node.rb', line 5728

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── name: #{name.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



5724
5725
5726
# File 'lib/yarp/node.rb', line 5724

def operator
  operator_loc.slice
end