Class: Prism::OptionalKeywordParameterNode

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

Overview

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

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

Explore code sample

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.

: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Prism::node value) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • name (Symbol)
  • name_loc (Location)
  • value (Prism::node)


25468
25469
25470
25471
25472
25473
25474
25475
25476
# File 'lib/prism/node.rb', line 25468

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

Class Method Details

.type ⇒ :optional_keyword_parameter_node

See Node.type.

: () -> :optional_keyword_parameter_node

Returns:

  • (:optional_keyword_parameter_node)


25557
25558
25559
# File 'lib/prism/node.rb', line 25557

def self.type
  :optional_keyword_parameter_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


25623
25624
25625
25626
25627
25628
25629
# File 'lib/prism/node.rb', line 25623

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

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


25492
25493
25494
# File 'lib/prism/node.rb', line 25492

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

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


25499
25500
25501
# File 'lib/prism/node.rb', line 25499

def child_nodes
  [value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


25516
25517
25518
# File 'lib/prism/node.rb', line 25516

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

:call-seq:

copy(**fields) -> OptionalKeywordParameterNode

Creates a copy of self with the given fields, using self as the template.

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

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • name: (Symbol) (defaults to: self.name)
  • name_loc: (Location) (defaults to: self.name_loc)
  • value: (Prism::node) (defaults to: self.value)

Returns:



25526
25527
25528
# File 'lib/prism/node.rb', line 25526

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) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
# File 'lib/prism/node.rb', line 25533

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location name name_loc value]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :name                    then deconstructed[:name] = self.name
    when :name_loc                then deconstructed[:name_loc] = self.name_loc
    when :value                   then deconstructed[:value] = self.value
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


25507
25508
25509
25510
25511
# File 'lib/prism/node.rb', line 25507

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  yield value
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


25562
25563
25564
# File 'lib/prism/node.rb', line 25562

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#name ⇒ Symbol

:call-seq:

name -> Symbol

Returns the name attribute.

: () -> Symbol

Returns:

  • (Symbol)


25582
25583
25584
# File 'lib/prism/node.rb', line 25582

def name
  @name
end

#name_loc ⇒ Location

:category: Locations :call-seq:

name_loc -> Location

Returns the Location represented by name_loc.

: () -> Location

Returns:



25593
25594
25595
25596
25597
# File 'lib/prism/node.rb', line 25593

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

:category: Flags a parameter name that has been repeated in the method signature

: () -> bool

Returns:

  • (Boolean)


25572
25573
25574
# File 'lib/prism/node.rb', line 25572

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

#save_name_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the name_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



25604
25605
25606
# File 'lib/prism/node.rb', line 25604

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

#type ⇒ :optional_keyword_parameter_node

See Node#type.

: () -> :optional_keyword_parameter_node

Returns:

  • (:optional_keyword_parameter_node)


25550
25551
25552
# File 'lib/prism/node.rb', line 25550

def type
  :optional_keyword_parameter_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

Returns the value attribute.

: () -> Prism::node

Returns:

  • (Prism::node)


25614
25615
25616
# File 'lib/prism/node.rb', line 25614

def value
  @value
end