/ruby/bob/bob.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Bob
  def hey(remark)
    remark.strip!
    if is_shouting?(remark)
      'Whoa, chill out!'
    elsif is_question?(remark)
      'Sure.'
    elsif is_silence?(remark)
      'Fine. Be that way!'
    else
      'Whatever.'
    end
  end

private
  def is_shouting?(remark)
    remark == remark.upcase and remark != remark.downcase
  end

  def is_question?(remark)
    remark.end_with? '?'
  end

  def is_silence?(remark)
    remark.empty?
  end
end

@Arkronus thinks this looks great

Comments

Now with private methods.

helenst commented 27 January 2015 at 21:20 UTC

You're not logged in right now. Please login via GitHub to comment