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.



16703
16704
16705
16706
16707
16708
16709
16710
# File 'lib/prism/node.rb', line 16703

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?



16761
16762
16763
# File 'lib/prism/node.rb', line 16761

def expression
  @expression
end

Class Method Details

.typeObject

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



16779
16780
16781
# File 'lib/prism/node.rb', line 16779

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.



16785
16786
16787
16788
16789
# File 'lib/prism/node.rb', line 16785

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



16713
16714
16715
# File 'lib/prism/node.rb', line 16713

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

#child_nodesObject Also known as: deconstruct

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



16718
16719
16720
# File 'lib/prism/node.rb', line 16718

def child_nodes
  [expression]
end

#comment_targetsObject

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



16730
16731
16732
# File 'lib/prism/node.rb', line 16730

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16723
16724
16725
16726
16727
# File 'lib/prism/node.rb', line 16723

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



16735
16736
16737
# File 'lib/prism/node.rb', line 16735

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



16743
16744
16745
# File 'lib/prism/node.rb', line 16743

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

#inspectObject

def inspect -> String



16769
16770
16771
# File 'lib/prism/node.rb', line 16769

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



16764
16765
16766
# File 'lib/prism/node.rb', line 16764

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



16748
16749
16750
16751
16752
# File 'lib/prism/node.rb', line 16748

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.



16756
16757
16758
# File 'lib/prism/node.rb', line 16756

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

#typeObject

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



16774
16775
16776
# File 'lib/prism/node.rb', line 16774

def type
  :splat_node
end