Last active
June 22, 2016 00:18
-
-
Save FioFiyo/aceb6f7c0f1ac4f79fb850aba1f397d9 to your computer and use it in GitHub Desktop.
Using loop and case within a method. Edit: removed variable from calling method, edited break so its within the loop and not outside(break if word == "go away"). Will edit to include clearer values in the loop to avoid 'woof' repetition.
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
require "pry-byebug" | |
#implement clear values within the loop | |
def barks_really_loud | |
puts "WOOF WOOF WOOF" | |
end | |
# create method to evaluate word | |
def behaviour | |
# # binding.pry | |
loop do | |
print "say something: " | |
word = gets.chomp.downcase | |
case word | |
when "woof" | |
#dont use puts since after calling the method | |
#its automatically returned plus a is puts down there. | |
barks_really_loud | |
when "meow" | |
puts "woof woof woof woof woof" | |
when /treat/ | |
puts "Shakil expects treat" | |
when "shakil stop" | |
puts "enjoy your moment of peace" | |
when "go away" | |
puts "Shakil leaves the room. :(" | |
break | |
else | |
puts "say something else: " | |
end | |
end | |
end | |
#call method | |
behaviour | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment