Module: RuboCop::AST::HashElementNode
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
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
-
#delimiter_delta(other) ⇒ Integer
Returns the delta between this element’s delimiter and the argument’s.
-
#key ⇒ Node
Returns the key of this
hash
element. -
#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
hash
element is on the same line asother
. -
#value ⇒ Node
Returns the value of this
hash
element. -
#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.
# 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.
# 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.
# 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
.
# 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.
# 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.
# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 52
def value_delta(other) HashElementDelta.new(self, other).value_delta end