From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-01-08T08:59:15+09:00 Subject: Re: Globals and passed objects (fixed) Nevermind.... I discovered that in one of the classes I do: #Tool.rb: class Tool @@results_dir = $RESULTS_DIR .... end and in the main client program I was defining $RESULTS_DIR _AFTER_ doing a require of Tool: #client: require 'Tool' .... $RESULTS_DIR = "/home/blah/results" so of course @@results_dir in class Tool was undefined (nil). Phil In article , Phil Tomson wrote: >This is related to an application of the Ruby Distributor. > >I'm distributing TestCase objects which have a 'run' method to clients. >On the clientside there is one global, $RESULTS_DIR, which is the path to >a directory where results are stored. Now, the server (Distributor) >instantiates a TestCase object which is then sent to a dRuby object on the >Client machine. The Client then invokes the TestCase objects 'run' >method which in turn creates several other objects on the client side. >One of the objects relies on $RESULTS_DIR to figure out where to store >it's results. But, $RESULTS_DIR in this context is nil even though we're >running on the client and the client program initially set up >$RESULTS_DIR. > >My theory is that as soon as we run the TestCase object's 'run' method on >the client that now TestCase doesn't know anything about the client's >globals since the TestCase object was created on the server machine. Does >this make sense? > >Here's some very chopped down code that I hope illustrates the problem: > >Server side: > >tc = TestCase.new() >distributor.send(tc) #this sends the testcase to the client machine > > >Client side: >$RESULTS_DIR="/home/results_dir" >... >#after receiveing the testcase, tc: >tc.run >#later, now somewhere in tc's run method: > File.copy(results, $RESULTS_DIR) > #but the copy doesn't succeed because $RESULTS_DIR is nil here > > > >Why wouldn't $RESULTS_DIR be visible in the context of the tc object's run >method? > >Phil >