module RuboCop::AST::HashElementNode

Common functionality for nodes that can be used as hash elements: `pair`, `kwsplat`

Public Instance Methods

delimiter_delta(other) click to toggle source

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 60
def delimiter_delta(other)
  HashElementDelta.new(self, other).delimiter_delta
end
key() click to toggle source

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 12
def key
  node_parts[0]
end
key_delta(other, alignment = :left) click to toggle source

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 42
def key_delta(other, alignment = :left)
  HashElementDelta.new(self, other).key_delta(alignment)
end
same_line?(other) click to toggle source

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 31
def same_line?(other)
  loc.last_line == other.loc.line || loc.line == other.loc.last_line
end
value() click to toggle source

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 21
def value
  node_parts[1]
end
value_delta(other) click to toggle source

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 51
def value_delta(other)
  HashElementDelta.new(self, other).value_delta
end