Class: RuboCop::AST::HashElementNode::HashElementDelta
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubocop/ast/node/mixin/hash_element_node.rb |
Overview
A helper class for comparing the positions of different parts of a
pair
node.
Class Method Summary
- .new(first, second) ⇒ HashElementDelta constructor
Instance Attribute Summary
- #first readonly private
- #keyword_splat? ⇒ Boolean readonly private
- #second readonly private
- #valid_argument_types? ⇒ Boolean readonly private
Instance Method Summary
Constructor Details
.new(first, second) ⇒ HashElementDelta
# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 68
def initialize(first, second) @first = first @second = second raise ArgumentError unless valid_argument_types? end
Instance Attribute Details
#first (readonly, private)
[ GitHub ]# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 98
attr_reader :first, :second
#keyword_splat? ⇒ Boolean
(readonly, private)
[ GitHub ]
#second (readonly, private)
[ GitHub ]# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 98
attr_reader :first, :second
#valid_argument_types? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 100
def valid_argument_types? [first, second].all? do |argument| # rubocop:disable InternalAffairs/NodeTypeMultiplePredicates argument.pair_type? || argument.kwsplat_type? # rubocop:enable InternalAffairs/NodeTypeMultiplePredicates end end
Instance Method Details
#delimiter_delta
[ GitHub ]#delta(first, second, alignment = :left) (private)
[ GitHub ]#key_delta(alignment = :left)
[ GitHub ]# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 75
def key_delta(alignment = :left) return 0 if first.same_line?(second) return 0 if keyword_splat? && alignment == :right delta(first.key.loc, second.key.loc, alignment) end
#value_delta
[ GitHub ]# File 'lib/rubocop/ast/node/mixin/hash_element_node.rb', line 82
def value_delta return 0 if first.same_line?(second) return 0 if keyword_splat? delta(first.value.loc, second.value.loc) end