class RuboCop::Cop::Lint::DeprecatedClassMethods
This cop checks for uses of the deprecated class method usages.
@example
# bad File.exists?(some_path) Dir.exists?(some_path) iterator?
@example
# good File.exist?(some_path) Dir.exist?(some_path) block_given?
Constants
- DEPRECATED_METHODS_OBJECT
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 72 def autocorrect(node) lambda do |corrector| check(node) do |data| corrector.replace(node.loc.selector, data.replacement_method.to_s) end end end
on_send(node)
click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 63 def on_send(node) check(node) do |data| message = format(MSG, current: deprecated_method(data), prefer: replacement_method(data)) add_offense(node, location: :selector, message: message) end end
Private Instance Methods
check(node) { |data| ... }
click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 83 def check(node) DEPRECATED_METHODS_OBJECT.each do |data| next unless data.class_nodes.include?(node.receiver) next unless node.method?(data.deprecated_method) yield data end end
deprecated_method(data)
click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 92 def deprecated_method(data) method_call(data.class_constant, data.deprecated_method) end
method_call(class_constant, method)
click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 100 def method_call(class_constant, method) if class_constant format('%<constant>s.%<method>s', constant: class_constant, method: method) else format('%<method>s', method: method) end end
replacement_method(data)
click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 96 def replacement_method(data) method_call(data.class_constant, data.replacement_method) end