Created
August 12, 2013 16:57
-
-
Save thenickcox/6212813 to your computer and use it in GitHub Desktop.
exercism.io solution to first problem
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 Bob | |
def hey(str) | |
@string = StringInterpreter.new(str) | |
handle_responses | |
end | |
private | |
def handle_responses | |
%w(blank exclamation question).each do |type| | |
return responder.send("#{type}_response") if @string.send("#{type}?") | |
end | |
responder.default_response | |
end | |
def responder | |
Responder.new | |
end | |
end | |
class StringInterpreter | |
attr_reader :string | |
def initialize(string) | |
@string = string | |
end | |
def blank? | |
string.nil? || string.empty? | |
end | |
def exclamation? | |
string.upcase == string | |
end | |
def question? | |
string =~ /\?$/ | |
end | |
end | |
class Responder | |
def blank_response | |
'Fine. Be that way.' | |
end | |
def exclamation_response | |
'Woah, chill out!' | |
end | |
def question_response | |
'Sure.' | |
end | |
def default_response | |
'Whatever.' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment