Class: Prism::KeywordHashNode

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

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.

[View source]

11335
11336
11337
11338
11339
11340
11341
# File 'lib/prism/node.rb', line 11335

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]


11382
11383
11384
# File 'lib/prism/node.rb', line 11382

def elements
  @elements
end

Class Method Details

.typeObject

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

[View source]

11395
11396
11397
# File 'lib/prism/node.rb', line 11395

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.

[View source]

11401
11402
11403
11404
11405
11406
# File 'lib/prism/node.rb', line 11401

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

[View source]

11344
11345
11346
# File 'lib/prism/node.rb', line 11344

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

#child_nodesObject Also known as: deconstruct

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

[View source]

11349
11350
11351
# File 'lib/prism/node.rb', line 11349

def child_nodes
  [*elements]
end

#comment_targetsObject

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

[View source]

11359
11360
11361
# File 'lib/prism/node.rb', line 11359

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array

[View source]

11354
11355
11356
# File 'lib/prism/node.rb', line 11354

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

[View source]

11364
11365
11366
# File 'lib/prism/node.rb', line 11364

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] }

[View source]

11372
11373
11374
# File 'lib/prism/node.rb', line 11372

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

#inspectObject

def inspect -> String

[View source]

11385
11386
11387
# File 'lib/prism/node.rb', line 11385

def inspect
  InspectVisitor.compose(self)
end

#symbol_keys?Boolean

def symbol_keys?: () -> bool

Returns:

  • (Boolean)
[View source]

11377
11378
11379
# File 'lib/prism/node.rb', line 11377

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

#typeObject

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

[View source]

11390
11391
11392
# File 'lib/prism/node.rb', line 11390

def type
  :keyword_hash_node
end