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.



1396
1397
1398
1399
1400
1401
1402
1403
# File 'lib/prism/node.rb', line 1396

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 }
    ^^^


1451
1452
1453
# File 'lib/prism/node.rb', line 1451

def value
  @value
end

Class Method Details

.typeObject

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



1485
1486
1487
# File 'lib/prism/node.rb', line 1485

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.



1491
1492
1493
1494
1495
# File 'lib/prism/node.rb', line 1491

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



1406
1407
1408
# File 'lib/prism/node.rb', line 1406

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



1411
1412
1413
# File 'lib/prism/node.rb', line 1411

def child_nodes
  [value]
end

#comment_targetsObject

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



1430
1431
1432
# File 'lib/prism/node.rb', line 1430

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1423
1424
1425
1426
1427
# File 'lib/prism/node.rb', line 1423

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



1435
1436
1437
# File 'lib/prism/node.rb', line 1435

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 }



1443
1444
1445
# File 'lib/prism/node.rb', line 1443

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

#each_child_node {|value| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



1416
1417
1418
1419
1420
# File 'lib/prism/node.rb', line 1416

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield value if value
end

#inspectObject

def inspect -> String



1475
1476
1477
# File 'lib/prism/node.rb', line 1475

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



1470
1471
1472
# File 'lib/prism/node.rb', line 1470

def operator
  operator_loc.slice
end

#operator_locObject

The location of the ‘**` operator.

{ **x }
  ^^


1457
1458
1459
1460
1461
# File 'lib/prism/node.rb', line 1457

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.



1465
1466
1467
# File 'lib/prism/node.rb', line 1465

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

#typeObject

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



1480
1481
1482
# File 'lib/prism/node.rb', line 1480

def type
  :assoc_splat_node
end