mileszs
11/14/2013 - 12:52 AM

bob.rb

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