Skip to content

Instantly share code, notes, and snippets.

@pumpchaser
Created November 7, 2012 06:33
Show Gist options
  • Save pumpchaser/4029859 to your computer and use it in GitHub Desktop.
Save pumpchaser/4029859 to your computer and use it in GitHub Desktop.
def compute_packages
packages = Packages.all # or however you get all your package
items = get_items #array of items
packages.each do |old_package|
items.each do |item|
old_package << item if old_package #if it has space (true), add the item
items.delete item if old_package #delete item, not sure if you can make this call inside of an iteration block
break if !old_package
end
end
while items
new_package = Package.new
items.each do |item|
new_package << item if new_package
items.delete item if new_package
break if !new_package
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment