Module: RuboCop::AST::HashElementNode

Included in:
KeywordSplatNode, PairNode
Defined in:
lib/rubocop/ast/node/mixin/hash_element_node.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#delimiter_delta(other) ⇒ Integer

Note:

Pairs with different delimiter styles return a delta of 0

Returns the delta between this element's delimiter and the argument's.


61
62
63
# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 61

def delimiter_delta(other)
  HashElementDelta.new(self, other).delimiter_delta
end

#keyNode

Note:

For keyword splats, this returns the whole node

Returns the key of this `hash` element.


13
14
15
# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 13

def key
  node_parts[0]
end

#key_delta(other, alignment = :left) ⇒ Integer

Note:

Keys on the same line always return a delta of 0

Note:

Keyword splats always return a delta of 0 for right alignment

Returns the delta between this pair's key and the argument pair's.


43
44
45
# 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

#same_line?(other) ⇒ Boolean

Note:

A multiline element is considered to be on the same line if it shares any of its lines with `other`

Checks whether this `hash` element is on the same line as `other`.


32
33
34
# 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

#valueNode

Note:

For keyword splats, this returns the whole node

Returns the value of this `hash` element.


22
23
24
# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 22

def value
  node_parts[1]
end

#value_delta(other) ⇒ Integer

Note:

Keyword splats always return a delta of 0

Returns the delta between this element's value and the argument's.


52
53
54
# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 52

def value_delta(other)
  HashElementDelta.new(self, other).value_delta
end