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.



10111
10112
10113
10114
10115
10116
10117
# File 'lib/prism/node.rb', line 10111

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]



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

def elements
  @elements
end

Class Method Details

.typeObject

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



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

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.



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

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



10120
10121
10122
# File 'lib/prism/node.rb', line 10120

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

#child_nodesObject Also known as: deconstruct

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



10125
10126
10127
# File 'lib/prism/node.rb', line 10125

def child_nodes
  [*elements]
end

#comment_targetsObject

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



10135
10136
10137
# File 'lib/prism/node.rb', line 10135

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



10130
10131
10132
# File 'lib/prism/node.rb', line 10130

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



10140
10141
10142
# File 'lib/prism/node.rb', line 10140

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



10148
10149
10150
# File 'lib/prism/node.rb', line 10148

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

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#symbol_keys?Boolean

def symbol_keys?: () -> bool

Returns:

  • (Boolean)


10153
10154
10155
# File 'lib/prism/node.rb', line 10153

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

#typeObject

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



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

def type
  :keyword_hash_node
end