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.



13816
13817
13818
13819
13820
13821
13822
13823
13824
# File 'lib/prism/node.rb', line 13816

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



13865
13866
13867
# File 'lib/prism/node.rb', line 13865

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



13881
13882
13883
# File 'lib/prism/node.rb', line 13881

def value
  @value
end

Class Method Details

.typeObject

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



13894
13895
13896
# File 'lib/prism/node.rb', line 13894

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.



13900
13901
13902
13903
13904
13905
13906
# File 'lib/prism/node.rb', line 13900

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



13827
13828
13829
# File 'lib/prism/node.rb', line 13827

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

#child_nodesObject Also known as: deconstruct

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



13832
13833
13834
# File 'lib/prism/node.rb', line 13832

def child_nodes
  [value]
end

#comment_targetsObject

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



13842
13843
13844
# File 'lib/prism/node.rb', line 13842

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



13837
13838
13839
# File 'lib/prism/node.rb', line 13837

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



13847
13848
13849
# File 'lib/prism/node.rb', line 13847

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 }



13855
13856
13857
# File 'lib/prism/node.rb', line 13855

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

#inspectObject

def inspect -> String



13884
13885
13886
# File 'lib/prism/node.rb', line 13884

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



13868
13869
13870
13871
13872
# File 'lib/prism/node.rb', line 13868

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)


13860
13861
13862
# File 'lib/prism/node.rb', line 13860

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.



13876
13877
13878
# File 'lib/prism/node.rb', line 13876

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

#typeObject

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



13889
13890
13891
# File 'lib/prism/node.rb', line 13889

def type
  :optional_keyword_parameter_node
end