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.



10148
10149
10150
10151
10152
10153
10154
# File 'lib/prism/node.rb', line 10148

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]



10195
10196
10197
# File 'lib/prism/node.rb', line 10195

def elements
  @elements
end

Class Method Details

.typeObject

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



10208
10209
10210
# File 'lib/prism/node.rb', line 10208

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.



10214
10215
10216
10217
10218
10219
# File 'lib/prism/node.rb', line 10214

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



10157
10158
10159
# File 'lib/prism/node.rb', line 10157

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

#child_nodesObject Also known as: deconstruct

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



10162
10163
10164
# File 'lib/prism/node.rb', line 10162

def child_nodes
  [*elements]
end

#comment_targetsObject

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



10172
10173
10174
# File 'lib/prism/node.rb', line 10172

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



10167
10168
10169
# File 'lib/prism/node.rb', line 10167

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



10177
10178
10179
# File 'lib/prism/node.rb', line 10177

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



10185
10186
10187
# File 'lib/prism/node.rb', line 10185

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

#inspectObject

def inspect -> String



10198
10199
10200
# File 'lib/prism/node.rb', line 10198

def inspect
  InspectVisitor.compose(self)
end

#symbol_keys?Boolean

def symbol_keys?: () -> bool

Returns:

  • (Boolean)


10190
10191
10192
# File 'lib/prism/node.rb', line 10190

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

#typeObject

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



10203
10204
10205
# File 'lib/prism/node.rb', line 10203

def type
  :keyword_hash_node
end