Skip to content

Instantly share code, notes, and snippets.

@cesare
Created July 25, 2013 14:49
Show Gist options
  • Save cesare/6080457 to your computer and use it in GitHub Desktop.
Save cesare/6080457 to your computer and use it in GitHub Desktop.
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.'
@cesare
Copy link
Author

cesare commented Jul 25, 2013

requires Ruby-2.0.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment