Created
January 29, 2014 20:55
-
-
Save cschneid/8696869 to your computer and use it in GitHub Desktop.
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
class Bob | |
RESPONSES = { | |
:shouting => "Woah, chill out!", | |
:silence => "Fine. Be that way.", | |
:question => "Sure.", | |
:statement => "Whatever.", | |
} | |
def hey(statement) | |
RESPONSES[interpret(statement.to_s)] | |
end | |
private | |
def interpret(statement) | |
return :silence if statement.empty? | |
return :shouting if all_uppercase?(statement) | |
return :question if ends_with_question_mark?(statement) | |
return :statement | |
end | |
def all_uppercase?(statement) | |
statement.upcase == statement | |
end | |
def ends_with_question_mark?(statement) | |
statement.end_with?("?") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment