Chapter 5Thursday: Class Definitions
As you know, writing object-oriented programs means spending a good chunk of your time defining classes. In Java and C#, defining a class is like making a deal between you and the compiler. You say, “Here’s how my objects are supposed to behave,” and the compiler replies, “Okay, they will.” Nothing really happens until you create an object of that class and then call that object’s methods.
In Ruby, class definitions are different. When you use the class keyword, you aren’t just dictating how objects will behave in the future. On the contrary, you’re actually running code.
If you buy into this notion—that a Ruby class definition is actually regular code that runs—you’ll be able to cast some powerful spells. ...