Last active
March 30, 2016 02:17
-
-
Save FioFiyo/9d684e0e9ca949cff2ff494d9f894118 to your computer and use it in GitHub Desktop.
Created a method to run a command sent by user for the dog to output certain things depending on the input.
This file contains 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 | |
a = "woof" | |
b = "shakil stop" | |
c = "meow" | |
d = "go away" | |
loop do | |
#getting input from the user | |
command = gets.chomp.downcase | |
break if command == "go away" | |
#evaluating the input with conditions | |
case command | |
when a | |
puts a * 3 | |
#trying to match a string condition | |
when /shakil stop!?/ || b | |
puts "enjoying the moment of peace" | |
when c | |
puts a * 5 | |
when /treat(.*)/ | |
puts "awaiting treat" | |
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