Ever get stuck on a problem, and then after staring at it for way too
long, get disgusted b/c there is no way to do it the way you need to
do it, and none of the workable alternatives quite cut it? Well,
that’s been my day.
I know it may seem a bit off the wall. But I want to subclass a class
that is also defined in the namespace of the subclass. In other words:
class X < Y
Why do I want to do this? Because my library (X) consists of a few
components, one of them being Y. And I want the end user of the
library to use it by typing “X.new”. Now, X is all but the same as Y,
with only with some minor adjustments.
Unfortunately for me there seems to be no way to do this without Ruby
complaining of a superclass mismatch.
In the end my alternatives appear to be:
- Use Z instead of X and fake it with X:
class Z < Y
- Delegate Y in X
@y = Y.new
def method_missing …
#1 sucks because I’m faking it --X isn’t really new. And #2 sucks
because it is nothing but a class wrapped around a single instance
variable --a complete waste of resources.
I imagine there is a tricky dynamic coding way to do it, but that will
screw up my RDocs.
Well, I don’t see any solution for it --if you have one I’ll be
amazed. But at least I got to vent.