Class: Prism::KeywordHashNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::KeywordHashNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Class Method Summary collapse
-
.type ⇒ :keyword_hash_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, elements: self.elements) ⇒ KeywordHashNode
:call-seq: copy(**fields) -> KeywordHashNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#elements ⇒ Array[AssocNode | AssocSplatNode]
:call-seq: elements -> Array[AssocNode | AssocSplatNode].
-
#initialize(source, node_id, location, flags, elements) ⇒ KeywordHashNode
constructor
Initialize a new KeywordHashNode node.
-
#inspect ⇒ String
: () -> String.
-
#symbol_keys? ⇒ Boolean
:category: Flags a keyword hash which only has
AssocNodeelements all with symbol keys, which means the elements can be treated as keyword arguments. -
#type ⇒ :keyword_hash_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, elements) ⇒ KeywordHashNode
Initialize a new KeywordHashNode node.
: (Source source, Integer node_id, Location location, Integer flags, Array[AssocNode | AssocSplatNode] elements) -> void
20764 20765 20766 20767 20768 20769 20770 |
# File 'lib/prism/node.rb', line 20764 def initialize(source, node_id, location, flags, elements) @source = source @node_id = node_id @location = location @flags = flags @elements = elements end |
Class Method Details
.type ⇒ :keyword_hash_node
See Node.type.
: () -> :keyword_hash_node
20849 20850 20851 |
# File 'lib/prism/node.rb', line 20849 def self.type :keyword_hash_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
20883 20884 20885 20886 20887 20888 |
# File 'lib/prism/node.rb', line 20883 def ===(other) # :nodoc: 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
See Node.accept.
: (_Visitor visitor) -> untyped
20786 20787 20788 |
# File 'lib/prism/node.rb', line 20786 def accept(visitor) visitor.visit_keyword_hash_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
20793 20794 20795 |
# File 'lib/prism/node.rb', line 20793 def child_nodes [*elements] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
20810 20811 20812 |
# File 'lib/prism/node.rb', line 20810 def compact_child_nodes [*elements] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, elements: self.elements) ⇒ KeywordHashNode
:call-seq:
copy(**fields) -> KeywordHashNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?elements: Array[AssocNode | AssocSplatNode]) -> KeywordHashNode
20820 20821 20822 |
# File 'lib/prism/node.rb', line 20820 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) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
20827 20828 20829 20830 20831 20832 20833 20834 20835 20836 20837 |
# File 'lib/prism/node.rb', line 20827 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location elements]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :elements then deconstructed[:elements] = self.elements end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
20801 20802 20803 20804 20805 |
# File 'lib/prism/node.rb', line 20801 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? elements.each { |node| yield node } end |
#elements ⇒ Array[AssocNode | AssocSplatNode]
:call-seq:
elements -> Array[AssocNode | AssocSplatNode]
Returns the elements attribute.
: () -> Array[AssocNode | AssocSplatNode]
20874 20875 20876 |
# File 'lib/prism/node.rb', line 20874 def elements @elements end |
#inspect ⇒ String
: () -> String
20854 20855 20856 |
# File 'lib/prism/node.rb', line 20854 def inspect # :nodoc: InspectVisitor.compose(self) end |
#symbol_keys? ⇒ Boolean
:category: Flags
a keyword hash which only has AssocNode elements all with symbol keys, which means the elements can be treated as keyword arguments
: () -> bool
20864 20865 20866 |
# File 'lib/prism/node.rb', line 20864 def symbol_keys? flags.anybits?(KeywordHashNodeFlags::SYMBOL_KEYS) end |
#type ⇒ :keyword_hash_node
See Node#type.
: () -> :keyword_hash_node
20842 20843 20844 |
# File 'lib/prism/node.rb', line 20842 def type :keyword_hash_node end |