Skip to content

Instantly share code, notes, and snippets.

@mayra-cabrera
Created August 22, 2015 23:47
Show Gist options
  • Save mayra-cabrera/ea28a1fb69bb183c5a6d to your computer and use it in GitHub Desktop.
Save mayra-cabrera/ea28a1fb69bb183c5a6d to your computer and use it in GitHub Desktop.
product_ids = [123,456,'',789]
products = product_ids.map{|id| Product.find(id)}
=> [#<Product:0x000123123 @name="TV"..>,
#<Product:0x000123124 @name="Cellphone"..>,
nil,
#<Product:0x000123125 @name="iPad"..>
]
products.each do |product|
if product && product.name
puts product.name
end
end
# "TV"
# "Cellphone"
# "iPad"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment