Class: Prism::KeywordRestParameterNode

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

Overview

Represents a keyword 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) ⇒ KeywordRestParameterNode

Initialize a new KeywordRestParameterNode node.

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

Parameters:



20908
20909
20910
20911
20912
20913
20914
20915
20916
# File 'lib/prism/node.rb', line 20908

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 ⇒ :keyword_rest_parameter_node

See Node.type.

: () -> :keyword_rest_parameter_node

Returns:



20997
20998
20999
# File 'lib/prism/node.rb', line 20997

def self.type
  :keyword_rest_parameter_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

Returns:



21090
21091
21092
21093
21094
21095
21096
# File 'lib/prism/node.rb', line 21090

def ===(other) # :nodoc:
  other.is_a?(KeywordRestParameterNode) &&
    (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:



20932
20933
20934
# File 'lib/prism/node.rb', line 20932

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

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

See Node.child_nodes.

: () -> Array

Returns:



20939
20940
20941
# File 'lib/prism/node.rb', line 20939

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:



20955
20956
20957
# File 'lib/prism/node.rb', line 20955

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

:call-seq:

copy(**fields) -> KeywordRestParameterNode

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) -> KeywordRestParameterNode

Parameters:

  • (defaults to: self.node_id)
  • (defaults to: self.location)
  • (defaults to: self.flags)
  • (defaults to: self.name)
  • (defaults to: self.name_loc)
  • (defaults to: self.operator_loc)

Returns:



20965
20966
20967
# File 'lib/prism/node.rb', line 20965

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)
  KeywordRestParameterNode.new(source, node_id, location, flags, name, name_loc, operator_loc)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

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

Parameters:

Returns:



20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
# File 'lib/prism/node.rb', line 20972

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:

  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


20947
20948
20949
20950
# File 'lib/prism/node.rb', line 20947

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

end

#inspect ⇒ String

: () -> String

Returns:



21002
21003
21004
# File 'lib/prism/node.rb', line 21002

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

#name ⇒ Symbol?

:call-seq:

name -> Symbol | nil

Returns the name attribute.

: () -> Symbol?

Returns:



21022
21023
21024
# File 'lib/prism/node.rb', line 21022

def name
  @name
end

#name_loc ⇒ Location?

:category: Locations :call-seq:

name_loc -> Location | nil

Returns the Location represented by name_loc.

: () -> Location?

Returns:



21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
# File 'lib/prism/node.rb', line 21033

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:



21083
21084
21085
# File 'lib/prism/node.rb', line 21083

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:



21060
21061
21062
21063
21064
# File 'lib/prism/node.rb', line 21060

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:



21012
21013
21014
# File 'lib/prism/node.rb', line 21012

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:



21050
21051
21052
# File 'lib/prism/node.rb', line 21050

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:



21071
21072
21073
# File 'lib/prism/node.rb', line 21071

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

#type ⇒ :keyword_rest_parameter_node

See Node#type.

: () -> :keyword_rest_parameter_node

Returns:



20990
20991
20992
# File 'lib/prism/node.rb', line 20990

def type
  :keyword_rest_parameter_node
end