Skip to content

Instantly share code, notes, and snippets.

@tim-br
Created June 30, 2015 21:06
Show Gist options
  • Save tim-br/e241d31b6dc4e056fb1a to your computer and use it in GitHub Desktop.
Save tim-br/e241d31b6dc4e056fb1a to your computer and use it in GitHub Desktop.
Shakil the dog work
# 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