Last active
September 8, 2017 20:12
-
-
Save flanger001/64f504111db0e98b73c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Now more objecty | |
class PotOfCoffee | |
attr_reader :scoops | |
def initialize(quantity: 12, strength: :normal) | |
@quantity = quantity | |
@strength = strength | |
end | |
def ratio | |
@ratio = { weak: 0.5, normal: 0.75, extra: 0.875, turbo: 1, omg: 2, wtf: 3.8 } | |
end | |
def scoops | |
quantity * ratio.fetch(strength) | |
rescue KeyError | |
"I don't know how to make #{strength} strength coffee, sorry." | |
end | |
end | |
pot = PotOfCoffee.new | |
puts pot.scoops # 9.0 | |
extra_pot = PotOfCoffee.new(quantity: 8, strength: :extra) | |
puts extra_pot.scoops # 7.0 | |
wtf_pot = PotOfCoffee.new(quantity: 12, strength: :wtf) | |
puts wtf_pot.scoops # 45.599999999999994 | |
error_pot = PotOfCoffee.new(quantity: 12, strength: 'asdgas') | |
puts error_pot.scoops # "I don't know how to make asdgas strength coffee, sorry." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you're too tightly coupling the concept of a Scoop and a Pot. They are clearly different objects with different behaviors.