Using a Ruby map on a range

Viewed 4739

I'm trying to use .map so I don't need to initialize a products array.

Here's the original code:

products = []
for page in (1..(ShopifyAPI::Product.count.to_f/150.0).ceil)
  products += ShopifyAPI::Product.find(:all, :params => {:page => page, :limit => 150})
end

Here's what I've tried:

products = (1..(ShopifyAPI::Product.count.to_f/150.0).ceil).map do |page|
  ShopifyAPI::Product.find(:all, :params => {:page => page.to_i, :limit => 150})
end

Which only returns the first product? What am I doing wrong?

The ShopifyAPI::Product returns a list of products based on the sent parameters page, and limit.

1 Answers
Related