Class: Prism::KeywordHashNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::KeywordHashNode
- 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
-
#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
#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
#elements ⇒ Object (readonly)
attr_reader elements: Array[AssocNode | AssocSplatNode]
10195 10196 10197 |
# File 'lib/prism/node.rb', line 10195 def elements @elements end |
Class Method Details
.type ⇒ Object
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_nodes ⇒ Object 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_targets ⇒ Object
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_nodes ⇒ Object
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 |
#inspect ⇒ Object
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
10190 10191 10192 |
# File 'lib/prism/node.rb', line 10190 def symbol_keys? flags.anybits?(KeywordHashNodeFlags::SYMBOL_KEYS) end |
#type ⇒ Object
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 |