Class: YARP::KeywordHashNode

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

Overview

Represents a hash literal without opening and closing braces.

foo(a: b)
    ^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements, location) ⇒ KeywordHashNode

def initialize: (elements: Array, location: Location) -> void



4570
4571
4572
4573
# File 'lib/yarp/node.rb', line 4570

def initialize(elements, location)
  @elements = elements
  @location = location
end

Instance Attribute Details

#elementsObject (readonly)

attr_reader elements: Array



4567
4568
4569
# File 'lib/yarp/node.rb', line 4567

def elements
  @elements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



4576
4577
4578
# File 'lib/yarp/node.rb', line 4576

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

#child_nodesObject Also known as: deconstruct

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



4581
4582
4583
# File 'lib/yarp/node.rb', line 4581

def child_nodes
  [*elements]
end

#copy(**params) ⇒ Object

def copy: (**params) -> KeywordHashNode



4586
4587
4588
4589
4590
4591
# File 'lib/yarp/node.rb', line 4586

def copy(**params)
  KeywordHashNode.new(
    params.fetch(:elements) { elements },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



4597
4598
4599
# File 'lib/yarp/node.rb', line 4597

def deconstruct_keys(keys)
  { elements: elements, location: location }
end