class RubbyCop::Cop::Performance::Caller

This cop identifies places where `caller` can be replaced by `caller(n..n).first`.

@example

# bad
caller[n]
caller.first

# good
caller(n..n).first
caller(1..1).first

Constants

MSG
SCOPE_METHODS

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubbycop/cop/performance/caller.rb, line 25
def on_send(node)
  return unless caller_with_scope_method?(node) && slow_caller?(node)
  add_offense(node, :selector)
end

Private Instance Methods

slow_caller?(node) click to toggle source
# File lib/rubbycop/cop/performance/caller.rb, line 32
def slow_caller?(node)
  arguments = node.receiver.arguments

  arguments.empty? ||
    (arguments.length == 1 && arguments[0].int_type?)
end