Skip to content

Incorrect recommendation suggested by Performance/ChainArrayAllocation Cop #185

@ashmaroli

Description

@ashmaroli

Expected behavior

Expected RuboCop to suggest valid corrections.

Actual behavior

C: Performance/ChainArrayAllocation: Use unchained values_at! and compact! (followed by return array if required)
instead of chaining values_at...compact.

options.values_at("alpha", "beta", "gamma").compact.length > 1
                                           ^^^^^^^^

Problem

Hash instances do not respond to :values_at!

Steps to reproduce the problem

Run RuboCop against the following code:

def foo?(options = {})
  options.values_at("alpha", "beta", "gamma").compact.length > 1
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions