-
-
Save kaiguogit/6b8f70f95d39ed653295594d9637a17f to your computer and use it in GitHub Desktop.
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
# 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