Closed
Description
Expected behavior
No alerts for arrays.
Actual behavior
Rails/PluckId raises an alert when using pluck(:id)
with array collections.
Arrays does not support .ids
, that only works for ActiveRecord::Relation
collections.
Steps to reproduce the problem
I have this code:
array = [{ id: 1 }, { id: 2 }]
extracted_ids = array.pluck(:id)
Rubocop suggestion:
Rails/PluckId: Use ids instead of pluck(:id).
extracted_ids = array.pluck(:id)
^^^^^^^^^^
Updated code:
array = [{ id: 1 }, { id: 2 }]
extracted_ids = array.ids
Then it produces the following error:
NoMethodError: undefined method `ids' for [{:id=>1}, {:id=>2}]:Array
RuboCop version
bundle exec rubocop -V
0.88.0 (using Parser 2.7.1.4, rubocop-ast 0.2.0, running on ruby 2.7.1 x86_64-linux)
Metadata
Metadata
Assignees
Labels
No labels
Activity