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.



12424
12425
12426
12427
12428
12429
12430
12431
12432
# File 'lib/prism/node.rb', line 12424

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



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

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



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

def value
  @value
end

Class Method Details

.typeObject

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



12496
12497
12498
# File 'lib/prism/node.rb', line 12496

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.



12502
12503
12504
12505
12506
12507
12508
# File 'lib/prism/node.rb', line 12502

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



12435
12436
12437
# File 'lib/prism/node.rb', line 12435

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

#child_nodesObject Also known as: deconstruct

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



12440
12441
12442
# File 'lib/prism/node.rb', line 12440

def child_nodes
  [value]
end

#comment_targetsObject

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



12450
12451
12452
# File 'lib/prism/node.rb', line 12450

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



12445
12446
12447
# File 'lib/prism/node.rb', line 12445

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



12455
12456
12457
# File 'lib/prism/node.rb', line 12455

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 }



12463
12464
12465
# File 'lib/prism/node.rb', line 12463

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

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



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

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)


12468
12469
12470
# File 'lib/prism/node.rb', line 12468

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

#typeObject

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



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

def type
  :optional_keyword_parameter_node
end