Skip to content

Instantly share code, notes, and snippets.

@toddseller
Created December 21, 2015 07:29
Show Gist options
  • Save toddseller/84167eefae9e2eedb427 to your computer and use it in GitHub Desktop.
Save toddseller/84167eefae9e2eedb427 to your computer and use it in GitHub Desktop.
Finishing up our Dog Class
class Dog
def initialize(name, breed)
@name = name
@breed = breed
@hungry = false
@bored = false
@tired = false
end
def feed
puts "You just fed #{@name}, the #{@breed}."
@hungry = false
@bored = true
end
def bored
puts "You just played fetch with #{@name}, the #{@breed}."
@bored = false
@tired = true
end
def nap
puts "#{@name}, the #{@breed}, just woke up from a nap."
@tired = false
@hungry = true
end
def status
puts "#{@name}, the #{@breed}, sure looks happy!" if @hungry == false && @bored == false && @tired == false
puts "#{@name}, the #{@breed}, looks hungry! You better get out the kibble!" if @hungry == true
puts "#{@name}, the #{@breed}, wants to play fetch! I'll go get the ball." if @bored == true
puts "I think fetch really wore out little #{@name}, the #{@breed}. You better put him to bed!" if @tired == true
end
end
puppy = Dog.new('Atticus', 'German Shepherd')
puppy.status
>> "Atticus, the German Shepherd, sure looks happy!"
puppy.feed
>> "You just fed Atticus, the German Shepherd."
puppy.status
>> "Atticus, the German Shepherd, wants to play fetch! I'll go get the ball."
puppy.bored
>> "You just played fetch with Atticus, the German Shepherd."
puppy.status
>> "I think fetch really wore out little Atticus, the German Shepherd. You better put him to bed!"
puppy.nap
>> "Atticus, the German Shepherd, just woke up from a nap."
puppy.status
>> "Atticus, the German Shepherd, looks hungry! You better get out the kibble!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment