I had a funny situation today (simplified):
Ive a communication object of type Adapter, with a #send and a #receive method.
My application communicates with it by DRb.
So in my application, I have a DRbObject, lets say foo.
Now, calling
foo.send(msg, dest)
calls the #send on DRbObject, instead of Adapter.
Most easy fix would be of course to rename the send method. But, I'd like to stay as close to my documentation/underlying API as possible.
What do you think?
Should I rename the send method, or is there a neat (local) hack for this?
DRbObject does it's remote message routing magic with
#method_missing. So, clearly, we should undefine the#sendmethod fromfooso it will delegate to#method_missinginstead!foo.singleton_class.class_eval { undef_method :send }Or to do it in a more object-oriented way:
As for whether you should do this, that's up for debate.
It's actually "okay" to override/remove
#send, because everyone is supposed to know that you should always call#__send__instead. (In fact, if you look atDRbObject#method_missing, it calls#__send__.)On the other hand,
#sendis a pretty core concept of Ruby and might confuse future maintainers of the code.