class RuboCop::Cop::Performance::Caller
caller_locations(1..1).first
caller_locations(2..2).first
caller(1..1).first
caller(2..2).first
# good
caller_locations.first
caller_locations[1]
caller.first
caller[1]
# bad
@example
can be replaced by ‘caller(n..n).first`.
This cop identifies places where `caller`
def int_value(node)
def int_value(node) node.children[0] end
def message(node)
def message(node) method_name = node.receiver.method_name caller_arg = node.receiver.first_argument n = caller_arg ? int_value(caller_arg) : 1 if node.method_name == :[] m = int_value(node.first_argument) n += m format(MSG_BRACE, n: n, m: m, method: method_name) else format(MSG_FIRST, n: n, method: method_name) end end
def on_send(node)
def on_send(node) return unless caller_with_scope_method?(node) add_offense(node) end