Class: Prism::RestParameterNode

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

Overview

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

def a(*b)
      ^^
end

Explore code sample

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.

: (Source source, Integer node_id, Location location, Integer flags, Symbol? name, Location? name_loc, Location operator_loc) -> void

Parameters:



29257
29258
29259
29260
29261
29262
29263
29264
29265
# File 'lib/prism/node.rb', line 29257

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

Class Method Details

.type ⇒ :rest_parameter_node

See Node.type.

: () -> :rest_parameter_node

Returns:

  • (:rest_parameter_node)


29346
29347
29348
# File 'lib/prism/node.rb', line 29346

def self.type
  :rest_parameter_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


29439
29440
29441
29442
29443
29444
29445
# File 'lib/prism/node.rb', line 29439

def ===(other) # :nodoc:
  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

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


29281
29282
29283
# File 'lib/prism/node.rb', line 29281

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

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


29288
29289
29290
# File 'lib/prism/node.rb', line 29288

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


29304
29305
29306
# File 'lib/prism/node.rb', line 29304

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) ⇒ RestParameterNode

:call-seq:

copy(**fields) -> RestParameterNode

Creates a copy of self with the given fields, using self as the template.

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

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • name: (Symbol, nil) (defaults to: self.name)
  • name_loc: (Location, nil) (defaults to: self.name_loc)
  • operator_loc: (Location) (defaults to: self.operator_loc)

Returns:



29314
29315
29316
# File 'lib/prism/node.rb', line 29314

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) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
# File 'lib/prism/node.rb', line 29321

def deconstruct_keys(keys) # :nodoc:
  (keys || i[node_id location name name_loc operator_loc operator]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :name                    then deconstructed[:name] = self.name
    when :name_loc                then deconstructed[:name_loc] = self.name_loc
    when :operator_loc            then deconstructed[:operator_loc] = self.operator_loc
    when :operator                then deconstructed[:operator] = self.operator
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


29296
29297
29298
29299
# File 'lib/prism/node.rb', line 29296

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


29351
29352
29353
# File 'lib/prism/node.rb', line 29351

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#name ⇒ Symbol?

:call-seq:

name -> Symbol | nil

Returns the name attribute.

: () -> Symbol?

Returns:

  • (Symbol, nil)


29371
29372
29373
# File 'lib/prism/node.rb', line 29371

def name
  @name
end

#name_loc ⇒ Location?

:category: Locations :call-seq:

name_loc -> Location | nil

Returns the Location represented by name_loc.

: () -> Location?

Returns:



29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
# File 'lib/prism/node.rb', line 29382

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

#operator ⇒ String

:call-seq:

operator -> String

Slice the location of operator_loc from the source.

: () -> String

Returns:

  • (String)


29432
29433
29434
# File 'lib/prism/node.rb', line 29432

def operator
  operator_loc.slice
end

#operator_loc ⇒ Location

:category: Locations :call-seq:

operator_loc -> Location

Returns the Location represented by operator_loc.

: () -> Location

Returns:



29409
29410
29411
29412
29413
# File 'lib/prism/node.rb', line 29409

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

:category: Flags a parameter name that has been repeated in the method signature

: () -> bool

Returns:

  • (Boolean)


29361
29362
29363
# File 'lib/prism/node.rb', line 29361

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

#save_name_loc(repository) ⇒ Relocation::Entry?

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

: (_Repository repository) -> Relocation::Entry?

Parameters:

Returns:



29399
29400
29401
# File 'lib/prism/node.rb', line 29399

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

#save_operator_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



29420
29421
29422
# File 'lib/prism/node.rb', line 29420

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

#type ⇒ :rest_parameter_node

See Node#type.

: () -> :rest_parameter_node

Returns:

  • (:rest_parameter_node)


29339
29340
29341
# File 'lib/prism/node.rb', line 29339

def type
  :rest_parameter_node
end