Skip to content

Instantly share code, notes, and snippets.

@kaiguogit
Forked from davidvandusen/shakil_the_dog.rb
Last active July 20, 2016 18:29
Show Gist options
  • Save kaiguogit/6b8f70f95d39ed653295594d9637a17f to your computer and use it in GitHub Desktop.
Save kaiguogit/6b8f70f95d39ed653295594d9637a17f to your computer and use it in GitHub Desktop.
# Save this file to your computer so you can run it
# via the command line (Terminal) like so:
# $ ruby shakil_the_dog.rb
#
# Your method should wait for user input, which corresponds
# to you saying something to your dog (named Shakil).
# You'll probably want to write other methods, but this
# encapsulates the core dog logic
def shakil_the_dog
begin
command = get_input
result = get_response(command)
puts result if result
end while command != 'go away'
puts 'Shakil has gone away'
end
def get_response(command)
case command
when "go away"
when "woof"
return "woof ".upcase * 3
when "Shakil STOP!","shakil stop", /treat/
when "meow"
return "woof " * 5
else
return "woof"
end
end
#get input
def get_input
print ">"
gets.strip()
end
# Run our method
shakil_the_dog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment