Class: YARP::GlobalVariableTargetNode

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

Overview

Represents writing to a global 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, location) ⇒ GlobalVariableTargetNode

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



4795
4796
4797
4798
# File 'lib/yarp/node.rb', line 4795

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol



4792
4793
4794
# File 'lib/yarp/node.rb', line 4792

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



4801
4802
4803
# File 'lib/yarp/node.rb', line 4801

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

#child_nodesObject Also known as: deconstruct

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



4806
4807
4808
# File 'lib/yarp/node.rb', line 4806

def child_nodes
  []
end

#comment_targetsObject

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



4811
4812
4813
# File 'lib/yarp/node.rb', line 4811

def comment_targets
  []
end

#copy(**params) ⇒ Object

def copy: (**params) -> GlobalVariableTargetNode



4816
4817
4818
4819
4820
4821
# File 'lib/yarp/node.rb', line 4816

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

#deconstruct_keys(keys) ⇒ Object

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



4827
4828
4829
# File 'lib/yarp/node.rb', line 4827

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

#inspect(inspector = NodeInspector.new) ⇒ Object



4831
4832
4833
4834
4835
# File 'lib/yarp/node.rb', line 4831

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