I have a collection like this:
UserLevels
id
blah_id
blah2_id
..
..
Now I want to further file this collection with all rows that have
blah2_id = 3
I don’t need to hit the database again as I already have this collection, and this collection will have maybe 5-10 rows in it anyhow at most.
What’s the best way to do this? Or what options do I have.
The first option that springs to mind is
Array#select(Ruby 1.9 only):Ruby’s
Arrayclass is quite powerful, and is worth investigating: http://www.ruby-doc.org/core/classes/Array.htmlIn Ruby 1.8, the equivalent method is
Enumerable#find_all: