You could wrap the File object owned by the Root in another object that
has the same interface as File, but passes methods to the actual File.

When the Root closes and reopens the file, it can change the File
reference in the wrapper.  The Child objects can keep reading from the
wrapper objects they have been given, oblivious to the fact that they
are now actually reading data from a different, hidden File object.

Cheers,
	Nat. 

On Wed, 2002-07-31 at 14:58, Bill Tj wrote:
> Hi,
> 
> Is there any easy way to emulate C pointer or C++ reference in Ruby?
> 
> Basically, the problem is something like this.  I have a root object,
> and it contains an instance variable that refers to, say, a file. 
> When the root object is created, it opens the file.  Then the root
> object creates many other child objects, passing the value of the file
> variable in the process.  Any child object will write to the same
> file.
> 
> Now, in the middle of execution, the root object may close the file,
> and some other program may access the file.  When the root object
> reopens the file, all the file variables in the child objects are no
> longer valid.  Therefore, I think it will be nice if the we can have
> some "reference" or "pointer", so that the child objects' file
> variables always point to the root object file variable.
> 
> The only solution that I can think of for now is for the root object
> to remember all the child objects, and to modify all the child
> objects' file variables whenever the root object file variable
> changes.  However, to me this is more like design pattern than a
> language feature.  (I read somewhere that in general the issue with
> programming languages is not whether something is possible, but rather
> whether the thing is facilitated.)
> 
> Regards,
> 
> Bill
-- 
Dr. Nathaniel Pryce, Technical Director, B13media Ltd.
Studio 3a, 22-24 Highbury Grove, London N5 2EA, UK
http://www.b13media.com