2 Comments »

This screencast goes through the Assignment 3 package. We’ll focus on:

  • The package layout. By and large this is a pretty standard layout for a Ruby application. (Not a Rails application — a plain Ruby application.)
  • The assignment (in the instructions/ directory).
  • The files you need to modify to finish the application.
  • What the demo.rb application looks like once your code is working.
  • What it would look like if your code passes all of the tests.
  • Three strategies for getting the assignment done:
    1. Think about the big picture, and about how you’d design your own application to determine the strength of a random selection of 5 cards according to the rules of poker. You might even write such an application. Then you would adapt it to satisfy the tests.
    2. Study the instructions/ web pages, and implement the code according to the various definitions of the classes and methods.
    3. Try to pass the tests one by one.
  • We believe that the best way to proceed is through a combination of 2 and 3. 1 is hard, because it may turn out that the semantics you come up with are at odds with the framework we’ve defined for the tests. So . . . we will walk through a bit of combining strategies 2 and 3, showing:
    1. The rake command (more on rake: Pickaxe, p. 229 [a bit out-of-date], and this tutorial: http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial
    2. What a test looks like (more: Pickaxe, chap. 12)
    3. How to interpret what a test “Error” or “Failure” means
  • That should be it.

A word to the wise: Writing code to tests will look bewildering at first, but once you start doing it, you will love it.

View (you will want to maximize your browser; to go “full-screen” in Firefox, press F11; then to turn off full-screen, press F11 again)

Errata:

  1. When I define the reader for @card_number, I say that I’m defining a local variable. In the heat of producing the screencast, I misspoke: It’s an instance variable.
  2. Also, when I’m nattering on about converting card_number in the appropriate suit, I say: card numbers 2 to 25 are Hearts. Of course I meant 13 to 25. I get these things wrong. That’s what computers are for!

“Computers are useless. They can only give you answers.” — Pablo Picasso