Skip to content

Instantly share code, notes, and snippets.

@pandafulmanda
Last active December 21, 2015 01:19
Show Gist options
  • Save pandafulmanda/6227335 to your computer and use it in GitHub Desktop.
Save pandafulmanda/6227335 to your computer and use it in GitHub Desktop.
A solution Bob in exercism.io
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