Skip to content

Instantly share code, notes, and snippets.

@thimo
Created March 31, 2025 11:36
Show Gist options
  • Save thimo/36e166962d6bd43c55dc0aa3df3c0d11 to your computer and use it in GitHub Desktop.
Save thimo/36e166962d6bd43c55dc0aa3df3c0d11 to your computer and use it in GitHub Desktop.
cart_calculator.rb
class CartCalculator
def initialize(products)
@products = products
end
# Calculate the total price including:
# - Sum of all product prices
# - Apply bulk discount: 10% off when total exceeds $100
# - Apply free shipping when total exceeds $50 (shipping cost is $10)
# Return a hash containing subtotal, discount, shipping, and final total
def calculate_total
# TODO: Implement this method
#
end
end
# Example product data structure:
# products = [
# { name: "Book", price: 20 },
# { name: "Pen", price: 5 }
# ]
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment