Last active
August 29, 2015 14:25
-
-
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.
This file contains 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
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