Ruby DRbObject and Submission Redirection

Today I had a funny situation (simplified):

Ive an #send object of type Adapter , with #send and #receive . My application communicates with it using DRb. So in my application I have DRbObject , say foo .

Now calling

 foo.send(msg, dest) 

calls #send on DRbObject instead of Adapter .

The simplest solution would, of course, be to rename the submit method. But I would like to be as close as possible to my documentation / core API.

What do you think? Should I rename the send method, or is there a clean (local) hack for this?

+4
source share
1 answer

DRbObject does this with the magic of routing remote mail using #method_missing . So, we need to undefine the #send method from foo , so it delegates instead of #method_missing !

foo.singleton_class.class_eval { undef_method :send }

Or do it in a more object oriented way:

 AdapterDRbObject < DRbObject undef_method :send end 

Regarding whether you need to do this, this is for discussion.

Actually, it’s β€œnormal” to override / delete #send , because everything is supposed to know that you should always call #__send__ . (Actually, if you look at DRbObject#method_missing , it calls #__send__ .)

#send , #send other hand, is a pretty basic Ruby concept and can confuse future code maintainers.

+1
source

Source: https://habr.com/ru/post/1437736/


All Articles