I'm trying to make a proxy object that transfers almost all method calls to a child object, essentially the delegator pattern. For the most part, I'm just using a BasicObject and passing every call with method_missing to the child object. So far, so good.
The trick is that try as I might, I can't fool Ruby's case operator, so I can't do:
x = Proxy.new(15)
Fixnum === x #=> false, no matter what I do
This of course makes any case x
operations fail, which means the proxies can't be handed off safely to other libraries.
I can't for the life of me figure out what === is using. The proxy works fine for all of the class-based introspection I know of, which is all correctly passed to the child object:
x.is_a?(Fixnum) #=> true
x.instance_of?(Fixnum) #=> true
x.kind_of?(Fixnum) #=> true
x.class #=> Fixnum
Is Module#===
just doing some kind of magic that can't be avoided?
Yeah, it is. Module#===
is implemented in C, examining the object's class hierarchy directly. It doesn't look like there's a way to fool it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With