Skip to content

Instantly share code, notes, and snippets.

@arches
Created December 9, 2013 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arches/7875352 to your computer and use it in GitHub Desktop.
Save arches/7875352 to your computer and use it in GitHub Desktop.
bob
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