0

Say I have a model Person. The model Person has an attribute 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?

1
  • if it is an ActiveRecord model, Person.where(:age => 20) seems like the best thing to do Commented May 27, 2014 at 17:38

1 Answer 1

3

Yes use select method.

 persons.select { |person| person.age == 20 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.