On Nov 21, 2008, at 11:44 AM, Fernando Perez wrote:

> I have the following array:
>
> [ product1, product2, product3 ]
>
> All products are of type Product. The Product class defines isntance
> attributes such as: title, description, price.
>
> Can I use include? to check if the array has a product which price is
> zero? if not what would I need to do? Iterate over each product and  
> set
> a variable if a match is found?

Given arr = [ product1, product2, product3 ], and you have a 'price'  
method on your products:

If you want to find the first item of price zero:

    arr.find { |prod| prod.price.zero? }

If you want to find all items of price zero:

    arr.select { |prod| prod.price.zero? }

If you just want to know that at least one item has zero price:

    arr.any? { |prod| prod.price.zero? }