Class: Prism::AssocSplatNode

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

Overview

Represents a splat in a hash literal.

{ **foo }
  ^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, value, operator_loc) ⇒ AssocSplatNode

Initialize a new AssocSplatNode node.



1305
1306
1307
1308
1309
1310
1311
1312
# File 'lib/prism/node.rb', line 1305

def initialize(source, node_id, location, flags, value, operator_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @value = value
  @operator_loc = operator_loc
end

Instance Attribute Details

#valueObject (readonly)

The value to be splatted, if present. Will be missing when keyword rest argument forwarding is used.

{ **foo }
    ^^^


1353
1354
1355
# File 'lib/prism/node.rb', line 1353

def value
  @value
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



1387
1388
1389
# File 'lib/prism/node.rb', line 1387

def self.type
  :assoc_splat_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



1393
1394
1395
1396
1397
# File 'lib/prism/node.rb', line 1393

def ===(other)
  other.is_a?(AssocSplatNode) &&
    (value === other.value) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



1315
1316
1317
# File 'lib/prism/node.rb', line 1315

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

#child_nodesObject Also known as: deconstruct

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



1320
1321
1322
# File 'lib/prism/node.rb', line 1320

def child_nodes
  [value]
end

#comment_targetsObject

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



1332
1333
1334
# File 'lib/prism/node.rb', line 1332

def comment_targets
  [*value, operator_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1325
1326
1327
1328
1329
# File 'lib/prism/node.rb', line 1325

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << value if value
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, operator_loc: self.operator_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node?, ?operator_loc: Location) -> AssocSplatNode



1337
1338
1339
# File 'lib/prism/node.rb', line 1337

def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, operator_loc: self.operator_loc)
  AssocSplatNode.new(source, node_id, location, flags, value, operator_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, value: Prism::node?, operator_loc: Location }



1345
1346
1347
# File 'lib/prism/node.rb', line 1345

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

#inspectObject

def inspect -> String



1377
1378
1379
# File 'lib/prism/node.rb', line 1377

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



1372
1373
1374
# File 'lib/prism/node.rb', line 1372

def operator
  operator_loc.slice
end

#operator_locObject

The location of the ‘**` operator.

{ **x }
  ^^


1359
1360
1361
1362
1363
# File 'lib/prism/node.rb', line 1359

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_operator_loc(repository) ⇒ Object

Save the operator_loc location using the given saved source so that it can be retrieved later.



1367
1368
1369
# File 'lib/prism/node.rb', line 1367

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



1382
1383
1384
# File 'lib/prism/node.rb', line 1382

def type
  :assoc_splat_node
end