Project 7
Short Straw
Sometimes when you have a group of people, you need to randomly select one of them to do something. Maybe that’s to go first in a game, to do a chore, or just for fun you want to see who is the last person standing (think musical chairs). One old game that’s sometimes used to pick somebody is to take a bundle of straws (or sticks or pencils), make them all the same size except for one of them, and then randomly pick from the bundle. Whoever gets the short straw is “out” (or wins, depending on how you look at it!).
This project is going to dive a little more deeply into the Array object you’ve been using in some of the prior projects. Up until now, I’ve just used it with some basic functionality, but here, you’ll see that it’s a pretty powerful tool. I’ll show you a few different ways to use arrays, and as a bonus, I’ll show you a few shortcuts you can use when working with arrays and classes.
Organizing a New Project
You’ll use Atom to create and edit your program. You’ll store this project in a single Ruby file. And you’ll use the terminal program to run, test, and play around with the short straw code.
- Start your terminal program and enter the ...
Get Ruby For Kids For Dummies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.