🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of GabFitzgerald

GabFitzgerald's solution

to Bob in the Crystal Track

Published at Aug 10 2020 · 0 comments
Test suite

Bob is a lackadaisical teenager. In conversation, his responses are very limited.

Bob answers 'Sure.' if you ask him a question.

He answers 'Whoa, chill out!' if you yell at him.

He answers 'Calm down, I know what I'm doing!' if you yell a question at him.

He says 'Fine. Be that way!' if you address him without actually saying anything.

He answers 'Whatever.' to anything else.

Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.


Follow the setup instructions for Crystal here:


More help installing can be found here:


Making the Test Suite Pass

Execute the tests with:

$ crystal spec

In each test suite all but the first test have been skipped.

Once you get a test passing, you can unskip the next one by changing pending to it.


Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=06

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


require "spec"
require "../src/*"

describe "Bob" do
  describe "#hey" do
    it "responds to stating something" do
      Bob.hey("Tom-ay-to, tom-aaaah-to.").should eq "Whatever."

    pending "responds to shouting something" do
      Bob.hey("WATCH OUT!").should eq "Whoa, chill out!"

    pending "responds to asking a question" do
      Bob.hey("Does this cryogenic chamber make me look fat?").should eq "Sure."

    pending "responds to talking forcefully" do
      Bob.hey("Let\'s go make out behind the gym!").should eq "Whatever."

    pending "responds to using acronyms in regular speech" do
      Bob.hey("It\'s OK if you don\'t want to go to the DMV.").should eq "Whatever."

    pending "responds to forceful questions" do
      Bob.hey("WHAT THE HELL WERE YOU THINKING?").should eq "Calm down, I know what I'm doing!"

    pending "responds to shouting numbers" do
      Bob.hey("1, 2, 3 GO!").should eq "Whoa, chill out!"

    pending "responds to only numbers" do
      Bob.hey("1, 2, 3").should eq "Whatever."

    pending "responds to question with only numbers" do
      Bob.hey("4?").should eq "Sure."

    pending "responds to shouting with special characters" do
      Bob.hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!").should eq "Whoa, chill out!"

    pending "responds to shouting with no exclamation mark" do
      Bob.hey("I HATE YOU").should eq "Whoa, chill out!"

    pending "responds to statement containing question mark" do
      Bob.hey("Ending with a ? means a question.").should eq "Whatever."

    pending "responds to prattling on" do
      Bob.hey("Wait! Hang on.  Are you going to be OK?").should eq "Sure."

    pending "responds to silence" do
      Bob.hey("").should eq "Fine. Be that way!"

    pending "responds to prolonged silence" do
      Bob.hey("   ").should eq "Fine. Be that way!"
# Please implement your solution to bob in this file
class Bob
    def self.hey(what_he_said)
        if what_he_said == "" || what_he_said.count("a-zA-Z0-9") == 0  
            "Fine. Be that way!"
        # responds to asking a question
        elsif what_he_said.split("")[-1] == "?"
            what_he_said == what_he_said.upcase && what_he_said.count("a-zA-Z") > 0 ? "Calm down, I know what I'm doing!" : "Sure."      
        # responds to shouting something
        elsif what_he_said == what_he_said.upcase
            what_he_said.count("a-zA-Z") == 0 ? "Whatever." : "Whoa, chill out!"         

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?