class RuboCop::Cop::Lint::EachWithObjectArgument

Checks if each_with_object is called with an immutable argument. Since the argument is the object that the given block shall make calls on to build something based on the enumerable that each_with_object iterates over, an immutable argument makes no sense. It's definitely a bug.

@example

# bad

sum = numbers.each_with_object(0) { |e, a| a += e }

@example

# good

num = 0
sum = numbers.each_with_object(num) { |e, a| a += e }

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_csend(node)
Alias for: on_send
on_send(node) click to toggle source
# File lib/rubocop/cop/lint/each_with_object_argument.rb, line 33
def on_send(node)
  each_with_object?(node) do |arg|
    return unless arg.immutable_literal?

    add_offense(node)
  end
end
Also aliased as: on_csend