How can you iterate through an array of objects and return the entire object if a certain attribute is correct?
I have the following in my rails app
arr
array_of_objects.select { |favor| favor.completed == false }
Will return all the objects that's completed is false.
You can also use find_all
instead of select
.
You need to use Enumerable#find_all to get the all matched objects.
array_of_objects.find_all { |favor| favor.completed == false }
For first case,
array_of_objects.reject(&:completed)
For second case,
array_of_objects.select(&:completed)