Created
June 29, 2013 17:49
-
-
Save austintaylor/5892027 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
class CLI | |
def process(input) | |
if input == "q" | |
puts "Goodbye" | |
elsif input == "tweet" | |
puts "tweeting" | |
elsif input == "dm" | |
puts "direct messaging" | |
elsif input == "help" | |
puts "helping" | |
end | |
end | |
end |
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
class CLI | |
class QuitCommand | |
def match?(input) | |
input == "q" | |
end | |
def execute | |
puts "Goodbye" | |
end | |
end | |
def TweetCommand | |
def match?(input) | |
input == "tweet" | |
end | |
def execute | |
puts "tweeting" | |
end | |
end | |
class DirectMessageCommand | |
def match?(input) | |
input == "dm" | |
end | |
def execute | |
puts "direct messaging" | |
end | |
end | |
class HelpCommand | |
def match?(input) | |
input == "help" | |
end | |
def execute | |
puts "helping" | |
end | |
end | |
class NoActionCommand | |
def match?(input) | |
true | |
end | |
def execute | |
end | |
end | |
def commands | |
quit = QuitCommand.new | |
tweet = TweetCommand.new | |
dm = DirectMessageCommand.new | |
help = HelpCommand.new | |
no_action = NoActionCommand.new | |
[quit, tweet, dm, help, no_action] | |
end | |
def command_for_input(input) | |
commands.find {|command| command.match?(input) } | |
end | |
def process(input) | |
command_for_input(input).execute | |
end | |
end |
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
process :: String -> IO () | |
process "q" = putStrLn "quitting" | |
process "tweet" = putStrLn "tweeting" | |
process "dm" = putStrLn "direct messaging" | |
process "help" = putStrLn "helping" | |
process _ = return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment