Class: RuboCop::Cop::Lint::StringToInt

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/lint/string_to_int.rb

Overview

This cop checks for possible calls to String#to_i instead of Kernel#.Integer.

Constant Summary collapse

MSG =
'Perhaps String#to_i is called? Use `Integer(str, base)`.'.freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/rubocop/cop/lint/string_to_int.rb', line 9

def on_send(node)
  receiver, method_name, * = *node

  return unless method_name == :to_i
  return unless check_receiver(receiver)

  add_offense(node, :expression)
end