Created
December 9, 2013 16:32
-
-
Save arches/7875352 to your computer and use it in GitHub Desktop.
bob
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
require 'forwardable' | |
class Bob | |
def hey(message) | |
message = Message.new(message) | |
case | |
when message.shouting? | |
"Woah, chill out!" | |
when message.question? | |
"Sure." | |
when message.empty? | |
"Fine. Be that way." | |
else | |
"Whatever." | |
end | |
end | |
private | |
class Message | |
extend Forwardable | |
def_delegators :@body, :empty?, :upcase, :end_with? | |
def initialize(body) | |
@body = body || "" | |
end | |
def shouting? | |
return false if empty? | |
@body == upcase | |
end | |
def question? | |
end_with? "?" | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment