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
array_of_objects.each { |favor| favor.completed == false } array_of_objects.each { |favor| favor.completed }
but for some reason these two return the same result! I have tried to replace each with collect, map, keep_if as well as !favor.completed instead of favor.completed == false and none of them worked!
each
collect
map
keep_if
!favor.completed
favor.completed == false
Any help is highly appreciated!
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.
find_all
select
2.1m questions
2.1m answers
60 comments
57.0k users