Permalink
Browse files

Mug may be sipped and gulped of

* Mug#sip takes a drink consuming 1 percent of the Mug's contents
* Mug#gulp takes a drink consuming 10 percent of the Mug's contents
* s/percent_empty/percent_filled/ and fixes semantic logic
  • Loading branch information...
iamvery committed Sep 17, 2013
1 parent be67688 commit 0826c3f3f993163ef64d169c3f2f5a7e60c4d82f
Showing with 21 additions and 6 deletions.
  1. +21 −6 mug.rb
27 mug.rb
@@ -1,21 +1,36 @@
class Mug
attr_reader :color, :content, :percent_empty
attr_reader :color, :content, :percent_filled
def initialize(color=:white)
@color = color
@percent_empty = 100
@color = color
@percent_filled = 0
end
def fill(liquid=:coffee)
@content = liquid
@percent_empty = 0
@content = liquid
@percent_filled = 100
end
def filled?
percent_empty < 100
percent_filled > 0
end
def empty?
!filled?
end
def sip
drink(1)
end
def gulp
drink(10)
end
private
def drink(percent)
raise "You're all out of #{content}" if empty?
@percent_filled -= percent
end
end

0 comments on commit 0826c3f

Please sign in to comment.