Created
July 29, 2013 06:35
-
-
Save yucao24hours/6102490 to your computer and use it in GitHub Desktop.
https://gist.github.com/yucato/6073280 でいただいたアドバイスをもとに書いたコード(「3回連続で'BYE'と叫ぶまで帰してくれないおばあちゃん」)その3 です。もとの問題:https://gist.github.com/yucato/6054328
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
count = 0 | |
puts 'Hello! May I help you?' | |
begin | |
word = gets.chomp | |
if word != 'BYE' | |
# BYE以外を話しかけられた時はきちんと答える | |
if word.upcase == word | |
puts "Well, it hasn't happened since #{(1930..1950).to_a.sample} !" | |
else | |
puts 'Huh? Could you speak up, please??' | |
end | |
count = 0 | |
else | |
# BYEと言われたときは聞こえないふりをして、何も答えない | |
count = count + 1 | |
end | |
end while count < 3 | |
puts 'Thanks. Come back anytime.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment