class RuboCop::Cop::Performance::ChainArrayAllocation
array
array.map! { |x| x.downcase }
array.flatten!
array.compact!
array = [“a”, “b”, “c”]
# good.
@example
faster to mutate when we know it’s safe.
new intermediate array that is promptly thrown away. Instead it is
Each of these methods (‘compact`, `flatten`, `map`) will generate a
array.compact.flatten.map { |x| x.downcase }
array = [“a”, “b”, “c”]
# bad
@example
This cop is used to identify usages of
def on_send(node)
def on_send(node) flat_map_candidate?(node) do |fm, sm, _| range = range_between( node.loc.dot.begin_pos, node.source_range.end_pos ) add_offense( node, location: range, message: format(MSG, method: fm, second_method: sm) ) end end