Skip to content

Instantly share code, notes, and snippets.

@jasonblanchard
Created January 19, 2015 23:31
Show Gist options
  • Select an option

  • Save jasonblanchard/b9f53c39593428a28a20 to your computer and use it in GitHub Desktop.

Select an option

Save jasonblanchard/b9f53c39593428a28a20 to your computer and use it in GitHub Desktop.
puts "Hi there, what can I do for you?"
while true do
print ">> "
input = gets.chomp.split
command = input[0]
args = input[1..input.length]
case command
when 'greet'
name = args[0]
puts "Hello, #{name}"
when 'time'
puts "The time is #{Time.now}"
when 'add'
output = args.inject(0) do |memo, n|
memo += n.to_i
memo
end
puts "The solution to #{args.join(' + ')} is #{output}"
puts "That was easy."
when 'order'
output = args.shuffle
puts output.join(', ')
when 'say'
puts "Bleep bloop bleep #{args.join(' ')}"
when 'quit'
puts "See ya!"
break
else
output = "Don't know how to #{command}"
if args
output += " with #{args.join(', ')}"
end
puts output + ":("
puts "I only do 'greet', 'add', 'order', 'time', 'say', 'quit'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment