Class: Prism::KeywordRestParameterNode

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

Overview

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

Initialize a new KeywordRestParameterNode node.



11518
11519
11520
11521
11522
11523
11524
11525
11526
# File 'lib/prism/node.rb', line 11518

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?



11567
11568
11569
# File 'lib/prism/node.rb', line 11567

def name
  @name
end

Class Method Details

.typeObject

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



11617
11618
11619
# File 'lib/prism/node.rb', line 11617

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



11623
11624
11625
11626
11627
11628
11629
# File 'lib/prism/node.rb', line 11623

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

def accept: (Visitor visitor) -> void



11529
11530
11531
# File 'lib/prism/node.rb', line 11529

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



11534
11535
11536
# File 'lib/prism/node.rb', line 11534

def child_nodes
  []
end

#comment_targetsObject

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



11544
11545
11546
# File 'lib/prism/node.rb', line 11544

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



11539
11540
11541
# File 'lib/prism/node.rb', line 11539

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



11549
11550
11551
# File 'lib/prism/node.rb', line 11549

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

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



11557
11558
11559
# File 'lib/prism/node.rb', line 11557

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

#inspectObject

def inspect -> String



11607
11608
11609
# File 'lib/prism/node.rb', line 11607

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location?



11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
# File 'lib/prism/node.rb', line 11570

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



11602
11603
11604
# File 'lib/prism/node.rb', line 11602

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



11589
11590
11591
11592
11593
# File 'lib/prism/node.rb', line 11589

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)


11562
11563
11564
# File 'lib/prism/node.rb', line 11562

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.



11584
11585
11586
# File 'lib/prism/node.rb', line 11584

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.



11597
11598
11599
# File 'lib/prism/node.rb', line 11597

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

#typeObject

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



11612
11613
11614
# File 'lib/prism/node.rb', line 11612

def type
  :keyword_rest_parameter_node
end