Skip to content

Instantly share code, notes, and snippets.

@austintaylor
Created June 29, 2013 17:49
Show Gist options
  • Save austintaylor/5892027 to your computer and use it in GitHub Desktop.
Save austintaylor/5892027 to your computer and use it in GitHub Desktop.
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
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
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