Chapter 11. OOP and Dynamic Features in Ruby
This is an unusual chapter. Whereas many of the chapters in this book deal with a specific problem subdomain such as strings or files, this one doesn't. If the "problem space" is viewed as stretching out on one axis of a graph, this chapter extends out on the other axis, encompassing a slice of each of the other areas. This is because object-oriented programming and dynamicity aren't problem domains themselves but are paradigms that can be applied to any problem whether it be system administration, low-level networking, or Web development.
For this reason, much of this chapter's information should already be familiar to a programmer who knows Ruby. In fact, the rest of the book wouldn't make sense without some of the fundamental knowledge here. Any Ruby programmer knows how to create a subclass, for instance.
This raises the question of what to include and what to exclude. Does every Ruby programmer know about the extend method? What about the instance_eval method? What is obvious to one person might be big news to another.
We have decided to err on the side of completeness. We include in this chapter some of the more esoteric tasks you might want to do with dynamic OOP in Ruby, but we also include the more routine tasks in case anyone is unfamiliar with them. We go right down to the simplest level because people won't agree on where the "middle" level ends. And we have tried to offer a little extra information even on the most basic of topics to justify their inclusion here. On the other hand, topics that are fully covered elsewhere in the book are omitted here.
We'll also make two other comments. First, there is nothing magical about dynamic OOP. Ruby's object orientation and its dynamic nature do interact with each other, but they aren't inherently interrelated; we put them in a single chapter largely for convenience. Second, some language features might be mentioned here that aren't strictly related to either topic. Consider this to be cheating, if you will. We wanted to put them somewhere.