It will continue along doing this until it runs out of superclasses. Then, it will start over by calling
method_missing on the original object (which, as you guessed, means it starts searching in that object??™s
class).
Now, here??™s why eigenclasses are sometimes called singleton classes. When you define methods using
an eigenclass, Ruby actually inserts a fake class object between the real class and your object. So if you
define a new to_s method for this object, Ruby will find that one before it finds the one defined in the class
with def to_s. This means there??™s only ever one instance of that special class object, and it only ever
applies to that one object. Similarly, if you use an eigenclass like we did at the beginning of the chapter, you
still make the special class, but it??™s inserted above the class??™s class. This is where metaprogramming can
really tweak some people??™s brains.
Now that we have our methods, we don??™t need to worry about method_missing picking up
any slack. It would be nice, however, to have some better error messages if we do happen to
type something wrong, so we can have it raise an error, since it couldn??™t find a column we were
talking about.
Pages:
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281