Created
October 22, 2015 15:10
-
-
Save siakaramalegos/a5dc4c4b548a43f7830a to your computer and use it in GitHub Desktop.
Class Cup
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
class Cup # use title case for classes and only classes | |
# Have to call it "initialize" for it to work | |
def initialize | |
puts "I'm alive! **SPARKLE**" | |
# This is an instance variable - all cups have independent drink_amounts | |
# Pretend like these are percentages | |
@drink_amount = 0 | |
end | |
def fill | |
puts "I'm full!" | |
@drink_amount = 100 | |
end | |
def empty | |
puts "I'm all out. :(" | |
@drink_amount = 0 | |
end | |
def sip amount = 5 | |
if @drink_amount == 0 | |
puts "Oh nooo! There's nothing left. Sad faces." | |
elsif amount > @drink_amount | |
puts "Mmm, tasty. Just took less than a full sip though." | |
@drink_amount = 0 | |
else | |
puts "Mmm, tasty. Just took a sip." | |
@drink_amount -= amount | |
end | |
end | |
def quantity | |
puts @drink_amount | |
@drink_amount | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment