Я бы предложил этот вариант.
class Person < ApplicationRecord
has_many :pets
def owns?(_pets)
pets_ids = pets.pluck(:id)
_pets.all? { |id| pets_ids.include? id }
end
end
Когда _pets = [1, 4, 5]
, вы можете иметь следующие случаи:
_pets = [1, 4, 5] # to checked
pets_ids = [1, 4] # from pluck
#=> false
_pets = [1, 4, 5] # to checked
pets_ids = [1, 4, 5] # from pluck
#=> true
_pets = [1, 4, 5] # to checked
pets_ids = [1, 4, 5, 6] # from pluck
#=> true