Created
October 3, 2013 01:25
-
-
Save octosteve/6803190 to your computer and use it in GitHub Desktop.
Covering classes
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
# Cup | |
# You can ask if it's full or not | |
# | |
# You can fill it | |
# You can empty | |
# if You try to empty it and it's empty is says "I'm already empty" | |
# if You try to fill it and it's full is says "I'm already full" | |
class Cup | |
attr_accessor :owner | |
# attr_reader :owner | |
# attr_writer :owner | |
def initialize | |
@cup = "empty" | |
@owner = "Coffeeshop" | |
end | |
#def owner | |
# @owner | |
#end | |
#def owner=(owner) # buyer is a representation of whatever you pass in. Number, string... doesn't matter | |
# # Syntactic sugar for owner = buyer | |
# @owner = owner | |
#end | |
def empty? | |
@cup == "empty" | |
end | |
def fill | |
if @cup == "full" | |
"I'm already full" | |
else | |
# what we did before | |
@cup = "full" | |
end | |
end | |
def empty | |
if @cup == "empty" | |
"I'm already empty" | |
else | |
# what we did before | |
@cup = "empty" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment