Class: Prism::KeywordHashNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::KeywordHashNode
- 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
-
#elements ⇒ Object
readonly
attr_reader elements: Array[AssocNode | AssocSplatNode].
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, elements: Array[AssocNode | AssocSplatNode] }.
-
#initialize(source, node_id, location, flags, elements) ⇒ KeywordHashNode
constructor
Initialize a new KeywordHashNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#symbol_keys? ⇒ Boolean
def symbol_keys?: () -> bool.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
permalink #initialize(source, node_id, location, flags, elements) ⇒ KeywordHashNode
Initialize a new KeywordHashNode node.
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
permalink #elements ⇒ Object (readonly)
attr_reader elements: Array[AssocNode | AssocSplatNode]
11382 11383 11384 |
# File 'lib/prism/node.rb', line 11382 def elements @elements end |
Class Method Details
permalink .type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
11395 11396 11397 |
# File 'lib/prism/node.rb', line 11395 def self.type :keyword_hash_node end |
Instance Method Details
permalink #===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
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 |
permalink #accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
11344 11345 11346 |
# File 'lib/prism/node.rb', line 11344 def accept(visitor) visitor.visit_keyword_hash_node(self) end |
permalink #child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
11349 11350 11351 |
# File 'lib/prism/node.rb', line 11349 def child_nodes [*elements] end |
permalink #comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
11359 11360 11361 |
# File 'lib/prism/node.rb', line 11359 def comment_targets [*elements] #: Array[Prism::node | Location] end |
permalink #compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
11354 11355 11356 |
# File 'lib/prism/node.rb', line 11354 def compact_child_nodes [*elements] end |
permalink #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
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 |
permalink #deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, elements: Array[AssocNode | AssocSplatNode] }
11372 11373 11374 |
# File 'lib/prism/node.rb', line 11372 def deconstruct_keys(keys) { node_id: node_id, location: location, elements: elements } end |
permalink #inspect ⇒ Object
def inspect -> String
11385 11386 11387 |
# File 'lib/prism/node.rb', line 11385 def inspect InspectVisitor.compose(self) end |
permalink #symbol_keys? ⇒ Boolean
def symbol_keys?: () -> bool
11377 11378 11379 |
# File 'lib/prism/node.rb', line 11377 def symbol_keys? flags.anybits?(KeywordHashNodeFlags::SYMBOL_KEYS) end |
permalink #type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
11390 11391 11392 |
# File 'lib/prism/node.rb', line 11390 def type :keyword_hash_node end |