Class: Prism::KeywordHashNode

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

Overview

Represents a hash literal without opening and closing braces.

foo(a: b)
    ^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, elements) ⇒ KeywordHashNode

Initialize a new KeywordHashNode node.



11437
11438
11439
11440
11441
11442
11443
# File 'lib/prism/node.rb', line 11437

def initialize(source, node_id, location, flags, elements)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @elements = elements
end

Instance Attribute Details

#elementsObject (readonly)

attr_reader elements: Array[AssocNode | AssocSplatNode]



11484
11485
11486
# File 'lib/prism/node.rb', line 11484

def elements
  @elements
end

Class Method Details

.typeObject

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



11497
11498
11499
# File 'lib/prism/node.rb', line 11497

def self.type
  :keyword_hash_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.



11503
11504
11505
11506
11507
11508
# File 'lib/prism/node.rb', line 11503

def ===(other)
  other.is_a?(KeywordHashNode) &&
    (flags === other.flags) &&
    (elements.length == other.elements.length) &&
    elements.zip(other.elements).all? { |left, right| left === right }
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



11446
11447
11448
# File 'lib/prism/node.rb', line 11446

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



11451
11452
11453
# File 'lib/prism/node.rb', line 11451

def child_nodes
  [*elements]
end

#comment_targetsObject

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



11461
11462
11463
# File 'lib/prism/node.rb', line 11461

def comment_targets
  [*elements] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



11456
11457
11458
# File 'lib/prism/node.rb', line 11456

def compact_child_nodes
  [*elements]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, elements: self.elements) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?elements: Array[AssocNode | AssocSplatNode]) -> KeywordHashNode



11466
11467
11468
# File 'lib/prism/node.rb', line 11466

def copy(node_id: self.node_id, location: self.location, flags: self.flags, elements: self.elements)
  KeywordHashNode.new(source, node_id, location, flags, elements)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, elements: Array[AssocNode | AssocSplatNode] }



11474
11475
11476
# File 'lib/prism/node.rb', line 11474

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

#inspectObject

def inspect -> String



11487
11488
11489
# File 'lib/prism/node.rb', line 11487

def inspect
  InspectVisitor.compose(self)
end

#symbol_keys?Boolean

def symbol_keys?: () -> bool

Returns:

  • (Boolean)


11479
11480
11481
# File 'lib/prism/node.rb', line 11479

def symbol_keys?
  flags.anybits?(KeywordHashNodeFlags::SYMBOL_KEYS)
end

#typeObject

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



11492
11493
11494
# File 'lib/prism/node.rb', line 11492

def type
  :keyword_hash_node
end