class RuboCop::Cop::Lint::DeprecatedClassMethods
Addrinfo.tcp(host, port).getnameinfo
Addrinfo.getaddrinfo(nodename, service)
ENV.to_h # ‘ENV.dup` cannot dup `ENV`, use `ENV.to_h` to get a copy of `ENV` as a hash.
ENV.to_h
ENV # `ENV.freeze` cannot prohibit changes to environment variables.
block_given?
Dir.exist?(some_path)
File.exist?(some_path)
# good
Socket.gethostbyaddr(host)
Socket.gethostbyname(host)
ENV.dup # Calling `Env.dup` raises `TypeError` since Ruby 3.1.
ENV.clone
ENV.freeze # Calling `Env.freeze` raises `TypeError` since Ruby 2.7.
iterator?
Dir.exists?(some_path)
File.exists?(some_path)
# bad
@example
Checks for uses of the deprecated class method usages.
def check(node)
def check(node) DEPRECATED_METHODS_OBJECT.each_key do |deprecated| next unless deprecated.class_nodes.include?(node.receiver) next unless node.method?(deprecated.method) yield deprecated end end
def on_send(node)
def on_send(node) check(node) do |deprecated| prefer = replacement(deprecated) message = format(MSG, current: deprecated, prefer: prefer) current_method = node.loc.selector add_offense(current_method, message: message) do |corrector| next unless deprecated.correctable? if (preferred_method = prefer.method) corrector.replace(current_method, preferred_method) else corrector.remove(node.loc.dot) corrector.remove(current_method) end end end end
def replacement(deprecated)
def replacement(deprecated) DEPRECATED_METHODS_OBJECT[deprecated] end