Created
November 14, 2013 00:52
-
-
Save mileszs/7459360 to your computer and use it in GitHub Desktop.
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(input) | |
input = Input.new(input) | |
if input.blank? | |
'Fine. Be that way.' | |
elsif input.shouting? | |
'Woah, chill out!' | |
elsif input.question? | |
'Sure.' | |
else | |
'Whatever.' | |
end | |
end | |
end | |
class Input | |
attr_accessor :string | |
def initialize(value) | |
self.string = value | |
end | |
def blank? | |
string.nil? || string.strip == '' | |
end | |
def shouting? | |
!blank? && string !~ /[a-z]/ | |
end | |
def question? | |
string =~ /\?$/ | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment