作者:159dzhqian449_734 | 来源:互联网 | 2023-07-31 18:54
篇首语:本文由编程笔记#小编为大家整理,主要介绍了ruby lambda_pricing.rb相关的知识,希望对你有一定的参考价值。
food_prices_before_tax = [9, 8, 7, 6, 5, 4, 3, 2, 1]
liquor_prices_before_tax = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
wine_prices_before_tax = [50, 40, 30, 20, 10]
food_tax = lambda { |price| price + (price * 0.07) }
liquor_tax = lambda { |price| price + (price * 0.17) }
tuesday_wine_discount = lambda { |price| price - (price * 0.15) }
food_prices_with_tax = food_prices_before_tax.map(&food_tax)
liquor_prices_with_tax = liquor_prices_before_tax.map(&liquor_tax)
wine_prices_with_tuesday_discount = wine_prices_before_tax.map(&tuesday_wine_discount)
wine_prices_with_tuesday_discount_and_tax = wine_prices_with_tuesday_discount.map(&liquor_tax)
p food_prices_with_tax
p liquor_prices_with_tax
p wine_prices_with_tuesday_discount
p wine_prices_with_tuesday_discount_and_tax
one_bottle_of_wine = 70
p liquor_tax.call(one_bottle_of_wine)
p liquor_tax.(one_bottle_of_wine)
p liquor_tax[one_bottle_of_wine]
costco_discount = ->(price) { price - (price * 0.05) }
car_prices = [70_000, 60_000, 50_000, 40_000]
car_prices.each do |car|
puts "With the Costco discount, the car costs: #{costco_discount.call(car)}"
end