Created
April 26, 2013 06:02
-
-
Save douglascamata/5465299 to your computer and use it in GitHub Desktop.
Another solution to this post (http://jumpstartlab.com/news/archives/2013/04/23/the-death-of-ifs) problem: use Ruby Not using objects.
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
def start | |
command = "" | |
commands = default_commands | |
add_command(commands, "follow", "following") | |
while command != "q" | |
printf "enter command: " | |
command = gets.chomp | |
process(command, commands) | |
end | |
end | |
def default_commands | |
commands = Hash.new | |
commands[:q] = "Goodbye" | |
commands[:tweet] = "tweeting" | |
commands[:dm] = "direct messaging" | |
commands[:help] = "helping" | |
commands | |
end | |
def add_command(commands, input, output) | |
commands[input.to_sym] = output | |
commands | |
end | |
def process(input, commands) | |
puts commands[input.to_sym] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment