class RuboCop::Cop::InternalAffairs::MethodNameEndWith
node.bang_method?
# good
node.method_name.to_s.end_with?(‘!’)
# bad
node.predicate_method?
# good
node.method_name.to_s.end_with?(‘?’)
# bad
node.assignment_method?
# good
node.method_name.to_s.end_with?(‘=’)
# bad
@example
defined in rubocop-ast instead of ‘method_name.end_with?`.
Checks potentially usage of method identifier predicates
def on_send(node)
def on_send(node) method_name_end_with?(node) do |method_name_node, end_with_arg| next unless method_name_node.receiver preferred_method = SUGGEST_METHOD_FOR_SUFFIX[end_with_arg.value] range = range(method_name_node, node) message = format(MSG, method_name: preferred_method, method_suffix: range.source) add_offense(range, message: message) do |corrector| corrector.replace(range, preferred_method) end end end
def range(method_name_node, node)
def range(method_name_node, node) range = if method_name_node.call_type? method_name_node.loc.selector else method_name_node.source_range end range_between(range.begin_pos, node.source_range.end_pos) end