-
-
Save pandafulmanda/6227335 to your computer and use it in GitHub Desktop.
A solution Bob in exercism.io
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 | |
def hey (message) | |
all_cases = {:silence? => 'Fine. Be that way!', :yelling? => 'Woah, chill out!', :asking? => 'Sure.'} | |
response = all_cases.keys.find do |meth_name| | |
send(meth_name, message) | |
end | |
all_cases.fetch(response, 'Whatever.') | |
end | |
def yelling? (message) | |
message.upcase == message | |
end | |
def asking? (message) | |
message[-1].chr == '?' | |
end | |
def silence? (message) | |
message.nil? || message.strip.empty? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment