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.



1141
1142
1143
1144
1145
1146
1147
1148
# File 'lib/prism/node.rb', line 1141

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


1189
1190
1191
# File 'lib/prism/node.rb', line 1189

def value
  @value
end

Class Method Details

.typeObject

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



1217
1218
1219
# File 'lib/prism/node.rb', line 1217

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.



1223
1224
1225
1226
1227
# File 'lib/prism/node.rb', line 1223

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



1151
1152
1153
# File 'lib/prism/node.rb', line 1151

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

#child_nodesObject Also known as: deconstruct

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



1156
1157
1158
# File 'lib/prism/node.rb', line 1156

def child_nodes
  [value]
end

#comment_targetsObject

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



1168
1169
1170
# File 'lib/prism/node.rb', line 1168

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1161
1162
1163
1164
1165
# File 'lib/prism/node.rb', line 1161

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



1173
1174
1175
# File 'lib/prism/node.rb', line 1173

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 }



1181
1182
1183
# File 'lib/prism/node.rb', line 1181

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

#inspectObject

def inspect -> String



1207
1208
1209
# File 'lib/prism/node.rb', line 1207

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



1202
1203
1204
# File 'lib/prism/node.rb', line 1202

def operator
  operator_loc.slice
end

#operator_locObject

The location of the ‘**` operator.

{ **x }
  ^^


1195
1196
1197
1198
1199
# File 'lib/prism/node.rb', line 1195

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

#typeObject

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



1212
1213
1214
# File 'lib/prism/node.rb', line 1212

def type
  :assoc_splat_node
end