So by looking at your changes, I modified my example s.rb as below:

require "drb"
require "a"

> class OD < Array
>   	include DRbUndumped
>  	def[](index)
> 	 if Thread.current['DRb']
>       return DRbObject.new(super)
>     else
>       super
>     end
>    end
> end
>
> od = OD.new
> od.push(A.new(1,2))

puts "at beginning, od[0].x = #{od[0].x.inspect}"

DRb.start_service('druby://localhost:9000', od)

---------------------------------------

This made it unnecessary to include DRbUndumped in class Foo and therefore,
I can now Marshal Foo to a pstore (or other places).

So thanks for that! :-)

This brings up more questions however.

1. What is DRb.install_id_conv(DRb::TimerIdConv.new) ? I didn't use it in my
code and everything worked OK, so what is it for?

2. In client2.rb you made a reference in db["bar"] to db["foo"] and it
turned out to be a local setting only. Is there a way to make that not
local? Would there be a way to create a Foo object on the client which
references objects on the server that when this Foo object is put to the
server the references are translated into local references to the objects on
the server?

Thanks again for your help.

Steve Tuckner


> -----Original Message-----
> From: Masatoshi SEKI [mailto:seki / mr.nasu.toshiba.co.jp]On Behalf Of
> m_seki / mva.biglobe.ne.jp
> Sent: Thursday, August 07, 2003 5:50 PM
> To: ruby-talk ML
> Subject: Re: [DRb] Using DRb to implement object database
>
>
>
> Hello, Steve.
>
> Do you want it?
> This database pass a root object by reference.
>
> --- foo.rb ---
> class Foo
>   def initialize(x, y)
>     @x = x
>     @y = y
>   end
>   attr_accessor :x, :y
> end
>
> --- db.rb ---
> require 'pstore'
> require 'drb/drb'
> require 'drb/timeridconv'
> require 'foo'
>
> class Database < PStore
>   include DRbUndumped
>   def [](key)
>     if Thread.current['DRb']
>       return DRbObject.new(super)
>     else
>       super
>     end
>   end
> end
>
> store = Database.new('test.db')
>
> DRb.install_id_conv(DRb::TimerIdConv.new)
> DRb.start_service('druby://localhost:12345', store)
> DRb.thread.join
>
> --- client.rb ---
> require 'drb/drb'
> require 'foo'
>
> def main
>   DRb.start_service
>   db = DRbObject.new_with_uri('druby://localhost:12345')
>   db.transaction do
>     db['foo'] = Foo.new(1, 2) unless db.root?('foo')
>   end
>   db.transaction do
>     foo = db['foo']        # pass by reference
>     foo.x = foo.x + 1
>   end
>   db.transaction do
>     foo = db['foo']
>     p [foo.x, foo.y, foo.class]
>   end
> end
>
> main
>
> --- client2.rb ---
> require 'drb/drb'
> require 'foo'
>
> def main
>   DRb.start_service
>   db = DRbObject.new_with_uri('druby://localhost:12345')
>   db.transaction do
>     db['foo'] = Foo.new(1, 2) unless db.root?('foo')
>     db['bar'] = Foo.new(db['foo'], 2) unless db.root?('bar')
>   end
>   db.transaction do
>     bar = db['bar']       # pass by reference
>     p bar
>     p bar.x               # pass by value
>     bar.x.x = bar.x.x + 1 # can't change bar.x.x
>     bar.y = bar.y + 1     # can change bar.y
>   end
>   db.transaction do
>     bar = db['bar']
>     p [bar.x, bar.y, bar.class]
>   end
> end
>
> main