Created
July 25, 2013 14:49
-
-
Save cesare/6080457 to your computer and use it in GitHub Desktop.
Inspired by @Yucato,
see also: https://gist.github.com/yucato/6073280
This file contains hidden or 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
puts 'Hello! May I help you?' | |
$stdin.lazy.reduce(Array.new 3) do |history, message| | |
history = ([message.strip!] + history).take 3 | |
break if history.all? {|msg| msg == 'BYE' } | |
reply = | |
case message | |
when 'BYE' | |
nil | |
when /^[[:upper:][:space:]]+$/ | |
"Well, it hasn't happened since #{(1930..1950).to_a.sample} !" | |
else | |
'Huh? Could you speak up, please??' | |
end | |
puts reply if reply | |
history | |
end | |
puts 'Thanks. Come back anytime.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires Ruby-2.0.x