Class: Prism::SplatNode

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

Overview

Represents the use of the splat operator.

[*a]
 ^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, operator_loc, expression) ⇒ SplatNode

Initialize a new SplatNode node.



15099
15100
15101
15102
15103
15104
15105
15106
# File 'lib/prism/node.rb', line 15099

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

Instance Attribute Details

#expressionObject (readonly)

attr_reader expression: Prism::node?



15151
15152
15153
# File 'lib/prism/node.rb', line 15151

def expression
  @expression
end

Class Method Details

.typeObject

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



15169
15170
15171
# File 'lib/prism/node.rb', line 15169

def self.type
  :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.



15175
15176
15177
15178
15179
# File 'lib/prism/node.rb', line 15175

def ===(other)
  other.is_a?(SplatNode) &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (expression === other.expression)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



15109
15110
15111
# File 'lib/prism/node.rb', line 15109

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

#child_nodesObject Also known as: deconstruct

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



15114
15115
15116
# File 'lib/prism/node.rb', line 15114

def child_nodes
  [expression]
end

#comment_targetsObject

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



15126
15127
15128
# File 'lib/prism/node.rb', line 15126

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15119
15120
15121
15122
15123
# File 'lib/prism/node.rb', line 15119

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

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

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



15131
15132
15133
# File 'lib/prism/node.rb', line 15131

def copy(node_id: self.node_id, location: self.location, flags: self.flags, operator_loc: self.operator_loc, expression: self.expression)
  SplatNode.new(source, node_id, location, flags, operator_loc, expression)
end

#deconstruct_keys(keys) ⇒ Object

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



15139
15140
15141
# File 'lib/prism/node.rb', line 15139

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

#inspectObject

def inspect -> String



15159
15160
15161
# File 'lib/prism/node.rb', line 15159

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



15154
15155
15156
# File 'lib/prism/node.rb', line 15154

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



15144
15145
15146
15147
15148
# File 'lib/prism/node.rb', line 15144

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`.



15164
15165
15166
# File 'lib/prism/node.rb', line 15164

def type
  :splat_node
end