Created
September 1, 2013 16:38
-
-
Save jacegu/6405591 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
defmodule Teenager do | |
import String | |
@reply_to_silence "Fine. Be that way!" | |
@reply_to_question "Sure." | |
@reply_to_shout "Woah, chill out!" | |
@reply_to_other "Whatever." | |
def hey(message) do | |
cond do | |
silence?(message) -> @reply_to_silence | |
question?(message) -> @reply_to_question | |
shout?(message) -> @reply_to_shout | |
other?(message) -> @reply_to_other | |
end | |
end | |
defp silence?(message), do: strip(message) == "" | |
defp question?(message), do: ends_with?(message, "?") | |
defp shout?(message), do: all_caps?(message) | |
defp other?(_message), do: true | |
defp all_caps?(message), do: message == upcase(message) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment