Chapter 5. OOP and Dynamicity in Ruby
IN THIS CHAPTER
Just as the introduction of the irrational
… is a convenient myth [which]
the laws of arithmetic… so physical objects are postulated entities which round out and simplify our account of the flux of existence…. The conceptional scheme of physical objects is [likewise] a
myth, simpler than the literal truth and yet containing that literal truth as a
Willard Van Orman Quine
This is an unusual chapter. Whereas most of the chapters in this book deal with a specific problem domain, this one doesn't. If the problem space is
as stretching out on one axis of a graph, this chapter extends out on the other axis, encompassing a slice of each of the problem domains. This is because object-oriented programming and dynamicity aren't problem domains
, but are
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
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
method? What about the
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
is unfamiliar with them. We go right down to the simplest level because people don'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 of all, there is nothing
about dynamic OOP. Ruby's object orientation and its dynamic nature do interact with each other, but they aren't
interrelated; we put them in a single chapter largely for convenience. Second, some language features might be mentioned here that aren't
to either topic. Consider this to be cheating, if you will. We wanted to put them