Skip to content

Instantly share code, notes, and snippets.

@octosteve
Created October 3, 2013 01:25
Show Gist options
  • Save octosteve/6803190 to your computer and use it in GitHub Desktop.
Save octosteve/6803190 to your computer and use it in GitHub Desktop.
Covering classes
# 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