Class: RuboCop::Cop::Gusto::MinByMaxBy
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Gusto::MinByMaxBy
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/gusto/min_by_max_by.rb
Overview
Checks for the use of ‘min` or `max` with a proc. Corrects to `min_by` or `max_by`.
Constant Summary collapse
- MSG =
"Use `%{method}_by` instead of `%{method}` with a proc like `&:my_method_proc`. `%{method}` expects Comparable elements."- RESTRICT_ON_SEND =
%i(min max).freeze
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
32 33 34 35 36 37 38 39 40 |
# File 'lib/rubocop/cop/gusto/min_by_max_by.rb', line 32 def on_send(node) return unless node.arguments? return unless node.first_argument.block_pass_type? method_name = node.method_name add_offense(node, message: format(MSG, method: method_name)) do |corrector| corrector.replace(node, node.source.sub(method_name.to_s, "#{method_name}_by")) end end |