Derby: DRb Over YAML #
Here’s Derby:
require 'drb/drb' require 'yaml' module DRb Marshal = ::YAML end
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 end
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 end
Which is because, for instance, Derby::DRbServer
still calls itself DRb::DRbServer
.
MenTaLguY
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 theDerby
rather than theDRb
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:
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.
MenTaLguY
Sadly, it almost seems like DRb was designed to defy extension.
In principle, you could define a
DRbMessage
subclass that simply replacedDRbMessage#load
andDRbMessage#dump
, but then who would use it?Okay, so you could write e.g. a
DRbTCPSocket
subclass which surreptitiously replaced its@msg
with your guerillaDrbMessage
knockoff (we’ve secretly replacedDRbTCPSocket'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.
why
Kxxx!
Kxxx! You just toured my past two days. You’re so on right now, M.
hgs
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.