Skip to content

Instantly share code, notes, and snippets.

@cschneid
Created January 29, 2014 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cschneid/8696869 to your computer and use it in GitHub Desktop.
Save cschneid/8696869 to your computer and use it in GitHub Desktop.
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