class RuboCop::AST::HashNode
to all ‘hash` nodes within RuboCop.
node when the builder constructs the AST, making its methods available
A node extension for `hash` nodes. This will be used in place of a plain
def braces?
-
(Boolean)
- whether the `hash` literal is enclosed in braces
def braces? loc.end&.is?('}') end
def each_key
-
(Enumerator)
- if no block is given -
(self)
- if a block is given
Other tags:
- Note: - `kwsplat` nodes are ignored.
def each_key return pairs.map(&:key).to_enum unless block_given? pairs.map(&:key).each do |key| yield key end self end
def each_pair
-
(Enumerator)
- if no block is given -
(self)
- if a block is given
Other tags:
- Note: - `kwsplat` nodes are ignored.
def each_pair return each_child_node(:pair).to_enum unless block_given? each_child_node(:pair) do |pair| yield(*pair) end self end
def each_value
-
(Enumerator)
- if no block is given -
(self)
- if a block is given
Other tags:
- Note: - `kwsplat` nodes are ignored.
def each_value return pairs.map(&:value).to_enum unless block_given? pairs.map(&:value).each do |value| yield value end self end
def empty?
Checks whether the `hash` node contains any `pair`- or `kwsplat` nodes.
def empty? children.empty? end
def keys
-
(Array
- an array of keys in the `hash` literal)
Other tags:
- Note: - `kwsplat` nodes are ignored.
def keys each_key.to_a end
def mixed_delimiters?
-
(Boolean)
- whether the `hash` uses mixed delimiters
Other tags:
- Note: - `kwsplat` nodes are ignored.
def mixed_delimiters? pairs.map(&:delimiter).uniq.size > 1 end
def pairs
-
(Array
- an array of `pair` nodes)
Other tags:
- Note: - this may be different from children as `kwsplat` nodes are
def pairs each_pair.to_a end
def pairs_on_same_line?
-
(Boolean)
- whether any `pair` nodes are on the same line
Other tags:
- Note: - `kwsplat` nodes are ignored.
Note: - A multiline `pair` is considered to be on the same line if it
def pairs_on_same_line? pairs.each_cons(2).any? { |first, second| first.same_line?(second) } end
def values
-
(Array
- an array of values in the `hash` literal)
Other tags:
- Note: - `kwsplat` nodes are ignored.
def values each_pair.map(&:value) end