-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcup.rb
37 lines (32 loc) · 824 Bytes
/
cup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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