An important note: These lessons are now updated and built into Hackety Hack. Don't bother reading them here on the wiki. Just run HH and click on the lightbulb icon in the toolbar. Much obliged! - _why
Lesson Four / Cheating
Approx. Time Needed: 10 mins.
Due Date: 24 Mar 2007
You've done some useful things. Downloaded files, built a simple blog. And lots more ahead. But let's stop and figure out how to speed up your learning.
Part A: Cheat Now
On the top toolbar of Hackety Hack, you'll see a series of little icons: a little house, a rainbow. Click on the magic wand icon. This icon brings up the Cheat Sheet.
You don't need to read the whole thing just yet. We're just going to glance over a few parts of it to get you comfortable with reading the Cheat Sheet. You can keep this out while you're writing programs in the main window.
Numbers
Let's read the second box on the Cheat Sheet, which talks about Numbers. Any Series of Digits.
Each box on the Cheat Sheet is carefully put together. On the left side, the title of the topic with an easy description. A Number. What is a Number? It's any series of digits! And, on the right side is a few short examples with the numbers highlighted in a color.
The two examples here illustrate two uses of numbers: first, multiplying a number. And, second, using a number with a method and a block.
In the main window, start a new program. Let's get multiplication working. Type in the first line of the program:
days = years * 365
Run it. Did it work? (It did not.) So, how can we fix this program? Try setting the years variable right before running that code.
And also add at the end: puts days
Move to the second example on the cheat sheet. Replace the days and years program with this:
5.times { puts "Odelay!" }
And that's it. These two examples are the key to using numbers. Numbers are for math. Or numbers are for repeating something.
Arrays
Move down to the fifth box on the cheat sheet. Arrays. A List of Things. We've seen Arrays before, too. So much is familiar to you already.
The Cheat Sheet gives another two examples to jog your memory about how Arrays work. The first example makes an Array of book titles.
books = ["Don Quixote", "Bluebeard"]
Type this in as a new program. Remember to puts the variable you're storing the Array in!
The second example in the Array cheat sheet has a bunch of variables named one, two and so on. The example makes an Array and then runs the each method with a block.
For extra credit: get that each method and its block hooked on to the books array in your new program!
Using Help
Keep the cheat sheet open to the Array section. Now go back to the main window and click the question mark icon (right next to the magic wand.)
This is the help manual! Click on "Array" on the left-hand side.
An Array is a list of things. Especially useful when you have some things you want to keep in a specific order.
The cheat sheet section on Arrays is just a small box. Not too much stuff there, just enough to get you thinking.
But in the help page on Arrays, you can scroll down for several pages, explaining the different methods available on an Array.
So: if you need to just remember some basic things, check the Cheat Sheet. If you need a lot more, hit the help pages.
Part B: Sample Programs
Close the help pages and return to the cheat sheet window. Scroll down, looking over each of the boxes. There are about ten boxes there -- blocks, methods, assorted things. This is so handy! It's all the basics of Ruby wrapped up in one page.
After those examples are a handful of sample programs. In fact, these are programs you wrote in the last few lessons. You can safely delete any programs you don't want because they are here on the Cheat Sheet in case you need them again.
Deleting Programs and Tables
We're finished with the cheat sheet, you can put it away. Go to the main Hackety Hack window and hit the "home" icon.
Under each Saved Program or Saved Table is a "delete" link. Use this link to scrap any of your programs or tables. Once deleted, they will be gone forever, but that's the whole idea, right?
If you'd like to empty out your blog entries, go ahead and delete the "MyBlog?" table by clicking its delete link.
Extra credit: try changing the name of your blog table in the program from last lesson. Add a few entries and come back to the home page. Did it show up?
