Created
June 30, 2015 21:06
-
-
Save tim-br/e241d31b6dc4e056fb1a to your computer and use it in GitHub Desktop.
Shakil the dog work
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 | |
regex = Regexp.new(Regexp.escape("treat"), Regexp::IGNORECASE) | |
while true | |
test = gets.chomp | |
if test == "woof" | |
4.times { puts "woof" } | |
elsif test.casecmp("shakil stop") == 0 | |
puts "quiet dog " | |
elsif test.casecmp("meow") == 0 | |
5.times {puts "woof"} | |
elsif regex.match(test) | |
puts "regex test" | |
elsif test.include?("happy") | |
puts "happy dog" | |
elsif test.casecmp("go away") == 0 | |
abort("the dog has left the room") | |
else | |
puts "woof" | |
end | |
end | |
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