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.



14833
14834
14835
14836
14837
14838
14839
14840
14841
# File 'lib/prism/node.rb', line 14833

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



14889
14890
14891
# File 'lib/prism/node.rb', line 14889

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



14905
14906
14907
# File 'lib/prism/node.rb', line 14905

def value
  @value
end

Class Method Details

.typeObject

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



14918
14919
14920
# File 'lib/prism/node.rb', line 14918

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.



14924
14925
14926
14927
14928
14929
14930
# File 'lib/prism/node.rb', line 14924

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



14844
14845
14846
# File 'lib/prism/node.rb', line 14844

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



14849
14850
14851
# File 'lib/prism/node.rb', line 14849

def child_nodes
  [value]
end

#comment_targetsObject

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



14866
14867
14868
# File 'lib/prism/node.rb', line 14866

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14861
14862
14863
# File 'lib/prism/node.rb', line 14861

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



14871
14872
14873
# File 'lib/prism/node.rb', line 14871

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 }



14879
14880
14881
# File 'lib/prism/node.rb', line 14879

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

#each_child_node {|value| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



14854
14855
14856
14857
14858
# File 'lib/prism/node.rb', line 14854

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield value
end

#inspectObject

def inspect -> String



14908
14909
14910
# File 'lib/prism/node.rb', line 14908

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



14892
14893
14894
14895
14896
# File 'lib/prism/node.rb', line 14892

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



14884
14885
14886
# File 'lib/prism/node.rb', line 14884

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.



14900
14901
14902
# File 'lib/prism/node.rb', line 14900

def save_name_loc(repository)
  repository.enter(node_id, :name_loc)
end

#typeObject

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



14913
14914
14915
# File 'lib/prism/node.rb', line 14913

def type
  :optional_keyword_parameter_node
end