Chapter 6. Ruby Two's Day
In This Chapter
Discovering object‐oriented programming in 25 pages or fewer
Using Ruby's iterators
Gathering code into modules
Think about something tiny — a tiny icon on a computer's screen. Magnify the icon's image by a factor of 7 or more. What do you see?
You see dots. You see jagged edges and blurs. If you magnify by a sufficiently large factor, you don't even see the original image. What once looked like a picture of a file folder becomes a meaningless field of light and dark pixels.
If you look at an image too closely and you ignore the big picture, you're likely to miss something important. A similar thing happens when you write computer programs. If you concentrate too much on each little statement and ignore the way statements are organized into larger units, you miss some important concepts.
Objects and Classes
An object is a single thing. Here's an employee object. The employee object has a name ("Barry Burd"), a hire date (2006‐06‐21), and a salary (1000000.00). And here's a second employee object. This second object has a different name ("Harriet Ritter"), a different hire date (2006‐06‐25), and a different salary (50000.00).
A class is a blueprint. The blueprint describes each one of a bunch of similar things. The Employee class says that each employee object has a name, a hire date, and a salary. The Employee class doesn't contain any particular name (such as "Barry Burd" or "Harriet Ritter"). The Employee class doesn't contain any particular hire ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access