Class: YARP::ConstantTargetNode

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

Overview

Represents writing to a constant 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) ⇒ ConstantTargetNode

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



3277
3278
3279
3280
# File 'lib/yarp/node.rb', line 3277

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol



3274
3275
3276
# File 'lib/yarp/node.rb', line 3274

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3283
3284
3285
# File 'lib/yarp/node.rb', line 3283

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

#child_nodesObject Also known as: deconstruct

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



3288
3289
3290
# File 'lib/yarp/node.rb', line 3288

def child_nodes
  []
end

#comment_targetsObject

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



3293
3294
3295
# File 'lib/yarp/node.rb', line 3293

def comment_targets
  []
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantTargetNode



3298
3299
3300
3301
3302
3303
# File 'lib/yarp/node.rb', line 3298

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



3309
3310
3311
# File 'lib/yarp/node.rb', line 3309

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

#inspect(inspector = NodeInspector.new) ⇒ Object



3313
3314
3315
3316
3317
# File 'lib/yarp/node.rb', line 3313

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