O'Reilly logo

Ruby on Rails For Dummies® by

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required