Created
March 24, 2020 15:27
-
-
Save eddiefisher/2a15eaa625336d71547089d4c9f4e9ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Delivery | |
WEIGHT_COEFFICIENT = 1 | |
VOLUME_COEFFICIENT = 1 | |
def initialize(order) | |
@order = order | |
end | |
def cost | |
@order.weight * WEIGHT_COEFFICIENT + @order.volume * VOLUME_COEFFICIENT | |
end | |
end | |
module Delivery::BubbleWrapped | |
def cost | |
super + 10 | |
end | |
end | |
module Delivery::UpToDoor | |
def cost | |
super + 15 | |
end | |
end | |
module Delivery::Dhl | |
def cost | |
super + SomeDhlApi.calculate(city) | |
end | |
end | |
order = Order.new(10, 5, 1, 1, "Moscow") | |
delivery = Delivery.new(order) | |
delivery.cost #=> 15 | |
delivery.extend(Delivery::Dhl) | |
delivery.cost #=> 115 | |
delivery.extend(Delivery::BubbleWrapped) | |
delivery.cost #=> 125 | |
delivery.extend(Delivery::UpToDoor) | |
delivery.cost #=> 140 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment