ned,
thanks for the response
yes yes PROXY. that's the ticket. i didn't realize that's what i'm
doing. and it acutally gives me an idea. i was looking at how ruby
creates objects and uses a proxy for mixins. wouldn't it be fantastic if
ruby supported networked-proxy objects interinsicly? think i'll suggest
it to matz.
thanks!
-tom
···
On Sun, 2002-09-08 at 12:06, Ned Konz wrote:
On Sunday 08 September 2002 11:02 am, Tom Sawyer wrote:
> like i said, ONI's turned into a very strange beast, and i'm not
> sure yet what to make of it. have i achived anything new really? or
> is all this already done in variant ways?
Sounds like a typical proxy-based remote object system (minus
distributed garbage collection, of course). This kind of thing is
pretty standard in Smalltalk, where we have #doesNotUnderstand:
instead of methodMissing().
--
tom sawyer, aka transami
transami@transami.net
i was looking at the way mixins build into the object models with proxy
objects. (see diagram on pickaxe p.247) i have been working on ONI and
Ned Konz pointed out that i had essentially created a remote-network
proxy object (note: very much still a work in progess):
class Module
public :undef_method # don't like this but what else is there?
end
module ONI
class Remote_Object
attr_reader :peer, :oid
def initialize(peer, oid)
@peer = peer
@oid = oid
methods.each { |mid|
if not ['inspect', 'instance_eval', 'instance_variables',
'__id__', 'id', 'new', 'methods', 'method_missing', 'oid', 'peer',
'to_yaml', 'undef_method', 'class', '__send__', 'send'].include?(mid)
self.class.undef_method(mid.intern)
end
}
end
def method_missing(mid, *args)
roargs = []
args.each { |obj|
if obj.is_a?(Remote_Object)
roargs << obj
else
oid = ONI::Peer.add(obj)
roargs < 'call',
'OID' => @oid,
'MID' => mid,
'ARG' => roargs
}
# connect
host, port = @peer.split(':')
port = port.to_i
session = TCPSocket.new(host, port)
# write
yreq = req.to_yaml
yreq_size = yreq.size
session.write([yreq_size].pack("N") + yreq)
# read
yam_size = session.read(4).unpack("N")[0]
yam = session.read(yam_size)
ro = YAML.load(yam)
session.close
return ro
end
end
end
taking the two together it occured to me that it would be awesome if
Ruby supported such remote-proxy objects “out-of-the-box”.
matz, are you listening?
-transami