Thank you for your answer but my question is how to add method to an
array of @products.
I have : @products.find(:all)
Then, if I want to select only fruits from @products, I could do :
@products.select {...}
And it's this select that I want to put in a method select_fruits so
that I could do :
@products.select_fruits which corresponds to @products.select { ... }
Although you don’t have to bother if you can tell by looking at a field. For example, if you have a “category” column that shows “fruit”, you can just use a dynamic finder for that
You should be letting your database do the work of filtering records, as that’s its job. You don’t want to iterate and reject / filter records in Ruby. It’s much slower. It looks cool but it’s not worth it.