Class: Prism::OptionalKeywordParameterNode

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

Overview

Represents an optional keyword parameter to a method, block, or lambda definition.

def a(b: 1)
      ^^^^
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, value) ⇒ OptionalKeywordParameterNode

Initialize a new OptionalKeywordParameterNode node.



12461
12462
12463
12464
12465
12466
12467
12468
12469
# File 'lib/prism/node.rb', line 12461

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol



12510
12511
12512
# File 'lib/prism/node.rb', line 12510

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



12520
12521
12522
# File 'lib/prism/node.rb', line 12520

def value
  @value
end

Class Method Details

.typeObject

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



12533
12534
12535
# File 'lib/prism/node.rb', line 12533

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



12539
12540
12541
12542
12543
12544
12545
# File 'lib/prism/node.rb', line 12539

def ===(other)
  other.is_a?(OptionalKeywordParameterNode) &&
    (flags === other.flags) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



12472
12473
12474
# File 'lib/prism/node.rb', line 12472

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

#child_nodesObject Also known as: deconstruct

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



12477
12478
12479
# File 'lib/prism/node.rb', line 12477

def child_nodes
  [value]
end

#comment_targetsObject

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



12487
12488
12489
# File 'lib/prism/node.rb', line 12487

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



12482
12483
12484
# File 'lib/prism/node.rb', line 12482

def compact_child_nodes
  [value]
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?value: Prism::node) -> OptionalKeywordParameterNode



12492
12493
12494
# File 'lib/prism/node.rb', line 12492

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

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, value: Prism::node }



12500
12501
12502
# File 'lib/prism/node.rb', line 12500

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

#inspectObject

def inspect -> String



12523
12524
12525
# File 'lib/prism/node.rb', line 12523

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



12513
12514
12515
12516
12517
# File 'lib/prism/node.rb', line 12513

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

#repeated_parameter?Boolean

def repeated_parameter?: () -> bool

Returns:

  • (Boolean)


12505
12506
12507
# File 'lib/prism/node.rb', line 12505

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

#typeObject

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



12528
12529
12530
# File 'lib/prism/node.rb', line 12528

def type
  :optional_keyword_parameter_node
end