colinramsay.co.uk

Ruby - Enumerable.collect

08 May 2005

This is great. Imagine I have a collection of ProductGroup objects, and I need to create an array of the id's of these objects. In Ruby I can just do this:

@product_group.Products.collect {|x| x.id }

This returns a new array containing id's of all the Products in @product_group.

Feedback or questions on this post? Create an issue on GitHub.