Class: Prism::RestParameterNode

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

Overview

Represents a rest parameter to a method, block, or lambda definition.

def a(*b)
      ^^
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, operator_loc) ⇒ RestParameterNode

Initialize a new RestParameterNode node.



17053
17054
17055
17056
17057
17058
17059
17060
17061
# File 'lib/prism/node.rb', line 17053

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol?



17108
17109
17110
# File 'lib/prism/node.rb', line 17108

def name
  @name
end

Class Method Details

.typeObject

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



17158
17159
17160
# File 'lib/prism/node.rb', line 17158

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



17164
17165
17166
17167
17168
17169
17170
# File 'lib/prism/node.rb', line 17164

def ===(other)
  other.is_a?(RestParameterNode) &&
    (flags === other.flags) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



17064
17065
17066
# File 'lib/prism/node.rb', line 17064

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



17069
17070
17071
# File 'lib/prism/node.rb', line 17069

def child_nodes
  []
end

#comment_targetsObject

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



17085
17086
17087
# File 'lib/prism/node.rb', line 17085

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



17080
17081
17082
# File 'lib/prism/node.rb', line 17080

def compact_child_nodes
  []
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol?, ?name_loc: Location?, ?operator_loc: Location) -> RestParameterNode



17090
17091
17092
# File 'lib/prism/node.rb', line 17090

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc)
  RestParameterNode.new(source, node_id, location, flags, name, name_loc, operator_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol?, name_loc: Location?, operator_loc: Location }



17098
17099
17100
# File 'lib/prism/node.rb', line 17098

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

#each_child_nodeObject

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



17074
17075
17076
17077
# File 'lib/prism/node.rb', line 17074

def each_child_node
  return to_enum(:each_child_node) unless block_given?

end

#inspectObject

def inspect -> String



17148
17149
17150
# File 'lib/prism/node.rb', line 17148

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location?



17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
# File 'lib/prism/node.rb', line 17111

def name_loc
  location = @name_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#operatorObject

def operator: () -> String



17143
17144
17145
# File 'lib/prism/node.rb', line 17143

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



17130
17131
17132
17133
17134
# File 'lib/prism/node.rb', line 17130

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

#repeated_parameter?Boolean

def repeated_parameter?: () -> bool

Returns:

  • (Boolean)


17103
17104
17105
# File 'lib/prism/node.rb', line 17103

def repeated_parameter?
  flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
end

#save_name_loc(repository) ⇒ Object

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



17125
17126
17127
# File 'lib/prism/node.rb', line 17125

def save_name_loc(repository)
  repository.enter(node_id, :name_loc) unless @name_loc.nil?
end

#save_operator_loc(repository) ⇒ Object

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



17138
17139
17140
# File 'lib/prism/node.rb', line 17138

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

#typeObject

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



17153
17154
17155
# File 'lib/prism/node.rb', line 17153

def type
  :rest_parameter_node
end