Skip to content

Instantly share code, notes, and snippets.

@bokmann
Last active August 29, 2015 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bokmann/b86534aa8bffab86de90 to your computer and use it in GitHub Desktop.
Save bokmann/b86534aa8bffab86de90 to your computer and use it in GitHub Desktop.
This is a work-in-progress. This is an example for students to learn the nature of using state in a class using instance variables. This could also break into an example of why threading is complicated, but thats not the first point of this example.
The KnockKnockinator
We're going to write a class that listens to and responds to knock knock jokes.
An interaction with this class should look like this:
> inator = KnockKnockInator.new
> response = inator.hears("Knock Knock")
#response == "Who's there?"
> response = inator.hears("A broken pencil.")
#response == "A broken pencil who?"
> response = inator.hears("Nevermind. It's pointless.")
# response == Any one of 5 or more random responses you make up, but it should always return the same response to the same joke (to the entire joke, not just the punchline).
If you start a new joke before finishing the old one, the class should just roll with it.
> inator = KnockKnockInator.new
> response = inator.hears("Knock Knock")
#response == "Who's there?"
> response = inator.hears("Knock Knock")
#response == "Who's there?"
> response = inator.hears("A broken pencil.")
#response == "A broken pencil who?"
> response = inator.hears("Knock Knock")
#response == "Who's there?"
The class should know how many jokes its heard:
> joke_count = inator.joke_count
# 42
If a joke is reset with a new Knock Knock before the punchline is heard, it doesn't count as a joke we've heard.
I'll write a test suite for this, you have to write the class.
http://www.buzzfeed.com/tabathaleggett/knock-knock-jokes-that-are-so-bad-theyre-good#.qj0J7zgNP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment