Skip to content

Commit

Permalink
Mug may be sipped and gulped of
Browse files Browse the repository at this point in the history
* 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 0826c3f
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions 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.