Skip to content

Instantly share code, notes, and snippets.

@FioFiyo
Last active June 22, 2016 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FioFiyo/aceb6f7c0f1ac4f79fb850aba1f397d9 to your computer and use it in GitHub Desktop.
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.
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