Class: YARP::ConstantWriteNode

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

Overview

Represents writing to a constant.

Foo = 1
^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_loc, value, operator_loc, location) ⇒ ConstantWriteNode

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



2345
2346
2347
2348
2349
2350
# File 'lib/yarp/node.rb', line 2345

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

Instance Attribute Details

#name_locObject (readonly)

attr_reader name_loc: Location



2336
2337
2338
# File 'lib/yarp/node.rb', line 2336

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



2342
2343
2344
# File 'lib/yarp/node.rb', line 2342

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



2339
2340
2341
# File 'lib/yarp/node.rb', line 2339

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2353
2354
2355
# File 'lib/yarp/node.rb', line 2353

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

#child_nodesObject Also known as: deconstruct

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



2358
2359
2360
# File 'lib/yarp/node.rb', line 2358

def child_nodes
  [value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantWriteNode



2363
2364
2365
2366
2367
2368
2369
2370
# File 'lib/yarp/node.rb', line 2363

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



2376
2377
2378
# File 'lib/yarp/node.rb', line 2376

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

#nameObject

def name: () -> String



2381
2382
2383
# File 'lib/yarp/node.rb', line 2381

def name
  name_loc.slice
end

#operatorObject

def operator: () -> String



2386
2387
2388
# File 'lib/yarp/node.rb', line 2386

def operator
  operator_loc.slice
end