module RuboCop::AST::HashElementNode
Common functionality for nodes that can be used as hash elements: `pair`, `kwsplat`
Public Instance Methods
Returns the delta between this element's delimiter and the argument's.
@note Pairs with different delimiter styles return a delta of 0
@return [Integer] the delta between the two delimiters
# File lib/rubocop/ast/node/mixin/hash_element_node.rb, line 61 def delimiter_delta(other) HashElementDelta.new(self, other).delimiter_delta end
Returns the key of this `hash` element.
@note For keyword splats, this returns the whole node
@return [Node] the key of the hash element
# File lib/rubocop/ast/node/mixin/hash_element_node.rb, line 13 def key node_parts[0] end
Returns the delta between this pair's key and the argument pair's.
@note Keys on the same line always return a delta of 0 @note Keyword splats always return a delta of 0 for right alignment
@param [Symbol] alignment whether to check the left or right side @return [Integer] the delta between the two keys
# File lib/rubocop/ast/node/mixin/hash_element_node.rb, line 43 def key_delta(other, alignment = :left) HashElementDelta.new(self, other).key_delta(alignment) end
Checks whether this `hash` element is on the same line as `other`.
@note A multiline element is considered to be on the same line if it
shares any of its lines with `other`
@return [Boolean] whether this element is on the same line as `other`
# File lib/rubocop/ast/node/mixin/hash_element_node.rb, line 32 def same_line?(other) loc.last_line == other.loc.line || loc.line == other.loc.last_line end
Returns the value of this `hash` element.
@note For keyword splats, this returns the whole node
@return [Node] the value of the hash element
# File lib/rubocop/ast/node/mixin/hash_element_node.rb, line 22 def value node_parts[1] end
Returns the delta between this element's value and the argument's.
@note Keyword splats always return a delta of 0
@return [Integer] the delta between the two values
# File lib/rubocop/ast/node/mixin/hash_element_node.rb, line 52 def value_delta(other) HashElementDelta.new(self, other).value_delta end