Class: YARP::AssocNode

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

Overview

Represents a hash key/value pair.

{ a => b }
  ^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, operator_loc, location) ⇒ AssocNode

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



328
329
330
331
332
333
# File 'lib/yarp/node.rb', line 328

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

Instance Attribute Details

#keyObject (readonly)

attr_reader key: Node



319
320
321
# File 'lib/yarp/node.rb', line 319

def key
  @key
end

#operator_locObject (readonly)

attr_reader operator_loc: Location?



325
326
327
# File 'lib/yarp/node.rb', line 325

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node?



322
323
324
# File 'lib/yarp/node.rb', line 322

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



336
337
338
# File 'lib/yarp/node.rb', line 336

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

#child_nodesObject Also known as: deconstruct

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



342
343
344
# File 'lib/yarp/node.rb', line 342

def child_nodes
  [key, value]
end

#deconstruct_keys(keys) ⇒ Object

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



350
351
352
# File 'lib/yarp/node.rb', line 350

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

#operatorObject

def operator: () -> String?



355
356
357
# File 'lib/yarp/node.rb', line 355

def operator
  operator_loc&.slice
end