Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Say I have a model Person. The model Person has an attribute age.
Person
age
If I have an array of Person-objects, how may I return a subarray containing only the Person-objects whose age-attribute is equal to, say, 20?
ActiveRecord
Person.where(:age => 20)
Yes use select method.
select
persons.select { |person| person.age == 20 }
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
ActiveRecordmodel,Person.where(:age => 20)seems like the best thing to do