hoodwink.d enhanced


Derby: DRb Over YAML #

by why in bits

Here’s Derby:

 require 'drb/drb'
 require 'yaml'

 module DRb
   Marshal = ::YAML

I’m still looking for a way to readdress the Derby module so it’ll work under its own namespace. I mean, imagine this:

 module Derby < DRb
   Marshal = ::YAML

I can’t seem to get the methods to rest under a new namespace, though, even with this sort of trickery:

 module Derby
   include DRb
   DRb.singleton_methods.each { |m| module_function m }
   Marshal = ::YAML

Which is because, for instance, Derby::DRbServer still calls itself DRb::DRbServer.

said on 29 Jun 2005 at 17:57

Oho! Admirable hack! You’re fortunate nobody had the tenacity to say ::Marshal in DRb.

As for your problem… DRb::DRbServer can call iself whatever it likes. You just need the identifier lookup to be happening via the Derby rather than the DRb namespace.

Sadly, as you’ve discovered, manipulating the namespace of an existing method just isn’t something that Ruby does. The method and the namespace in which it was defined are joined inseparably.

I mean, in its simplest form, basically what you are trying to do is this:

class HorseGreen
  KingZog = 3
  def self.hostelier; KingZog; end

class SparrowBlue < HorseGreen
  KingZog = 4

But you’re inexolerably getting SparrowBlue.hostelier => 3

Even the decisively evil:


(which would almost do what you wanted if it were permitted) won’t help you.

said on 29 Jun 2005 at 18:20

Sadly, it almost seems like DRb was designed to defy extension.

In principle, you could define a DRbMessage subclass that simply replaced DRbMessage#load and DRbMessage#dump, but then who would use it?

Okay, so you could write e.g. a DRbTCPSocket subclass which surreptitiously replaced its @msg with your guerilla DrbMessage knockoff (we’ve secretly replaced DRbTCPSocket's coffee with YAML crystals—let’s see if she notices…)...

But then if you want to coexist with traditional DRb marshalling you shall have to use a different protocol name (“druby-yaml:” perhaps)...

But the URI protocol names are all hardcoded in DRbTCPSocket methods, so you have to replace those wholesale too…

It’s almost probably easier to write a new DRbTCPSocket-alike from whole cloth (or judicious use of copy-and-paste) instead of reusing any of the existing code via composition or inheritance.

I find that a more than a little depressing.

said on 29 Jun 2005 at 18:43


we’ve secretly replaced DRbTCPSocket’s coffee with YAML crystals—let’s see if she notices…

Kxxx! You just toured my past two days. You’re so on right now, M.

said on 30 Jun 2005 at 16:33

As I disappear into the quicksand, I wonder if you can use the BACheater approach from the ‘Rock, Paper, Scissors’ Ruby Quiz and nobble the methods directly? Feels a bit dangerous to me…. hgs! Put that palantir down, and turn around slowly!

Comments are closed for this entry.