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
-
#delimiter_delta(other) ⇒ Integer
Returns the delta between this element’s delimiter and the argument’s.
-
#key ⇒ Node
Returns the key of this
hashelement. -
#key_delta(other, alignment = :left) ⇒ Integer
Returns the delta between this pair’s key and the argument pair’s.
-
#same_line?(other) ⇒ Boolean
Checks whether this
hashelement is on the same line asother. -
#value ⇒ Node
Returns the value of this
hashelement. -
#value_delta(other) ⇒ Integer
Returns the delta between this element’s value and the argument’s.
Instance Method Details
#delimiter_delta(other) ⇒ Integer
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 |
#key ⇒ Node
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
Keys on the same line always return a delta of 0
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
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 |
#value ⇒ Node
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
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 |