From: James Gray Date: 2008-01-15T22:58:09+09:00 Subject: Re: Attempted solution. :) On Jan 14, 2008, at 9:26 PM, James Gray wrote: > Begin forwarded message: > >> From: "Brian Knoll" >> Date: January 14, 2008 8:51:34 PM CST >> To: suggestion@rubyquiz.com >> Subject: Attempted solution. :) >> >> Hi, James, >> >> Thanks for doing Ruby Quiz -- it was very nice to have something to >> focus on, rather than inane training book examples (they try hard, >> they really do). >> Thanks for sending in a solution! >> I was hoping to get some feedback, as this is one of my first Ruby >> programs (not copied from a book or website). I've looked through the code a bit and have a suggestion: see if you can "DRY" the code up in places. DRY stands for Don't Repeat Yourself and it reminds us that if we're typing something over and over again, there's a better way. A simple example would be the Scite workaround you are using to print content immediately. You have a lot of lines like: puts … STDOUT.flush If we move that code into a method: def force_puts(*args) puts(*args) $stdout.flush end we can use that from now on. In this case though, Ruby has a variable to force flushing the output. If you set it at the top of your script, you can omit all of the calls to flush(): $| = true The biggest DRYing opportunity are the sections: if card_display == 1 # … end # … if card_display == 2 # … end # … if card_display == 3 # … end If you can condense those you can probably remove about 150 lines of code. That makes it easier to read and maintain, so it's a big win. Well, I hope that gives you some fresh ideas. James Edward Gray II