Method: RuboCop::Cop::Style::InverseMethods#autocorrect

Defined in:
lib/rubocop/cop/style/inverse_methods.rb

#autocorrect(node) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rubocop/cop/style/inverse_methods.rb', line 84

def autocorrect(node)
  method_call, _lhs, method, _rhs = inverse_candidate?(node)

  if method_call && method
    lambda do |corrector|
      corrector.remove(not_to_receiver(node, method_call))
      corrector.replace(method_call.loc.selector,
                        inverse_methods[method].to_s)

      if EQUALITY_METHODS.include?(method)
        corrector.remove(end_parentheses(node, method_call))
      end
    end
  else
    correct_inverse_block(node)
  end
end