Created
January 19, 2015 23:31
-
-
Save jasonblanchard/b9f53c39593428a28a20 to your computer and use it in GitHub Desktop.
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 "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