Ruby find and return objects in an array based on an attribute

后端 未结 3 593
后悔当初
后悔当初 2021-02-05 01:20

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         


        
3条回答
  •  无人及你
    2021-02-05 01:51

    You need to use Enumerable#find_all to get the all matched objects.

    array_of_objects.find_all { |favor| favor.completed == false }
    

提交回复
热议问题