I found something that works, I replaced the 'instance_eval' with
Object.class_eval  (see below).  Why didn't it work as a nested class?
Is this equivilent to what happens when you do a 'require'?

The string is being 'class_eval'ed into Object's class.

Phil


In article <STFM7.557491$Lg.22613900 / sjcpnn01.usenetserver.com>,
Phil Tomson <ptkwt / shell1.aracnet.com> wrote:
>
>I've got a class called Client that runs as a remote dRuby object.  Client 
>has a 'run' method which will in turn invoke a 'run' method on the object 
>which is passed in - I want users to be able to define new classes which 
>Client doesn't know about which have run methods.
>
>Here's part of Client.rb:
>
>class Client
>   attr_writer :clientTimeLimit
>   def initialize
>      @clientTimeLimit=99999 #assume an 'infinite' timelimit
>   end
>
>   def run(task,*args)
>      result = ""
>      if( task.respond_to?(:run))
>         result = task.run(args)
>      else
>         puts "task type is: #{task.type}"
>         result = "COULD_NOT_RUN" 
>      end
>      result
>   end
>
>   def remote_require(str)
>      puts "Client::remote_require(#{str})"
>      instance_eval str

I found that it works as I want if I change the previous line to:
       Object.class_eval str
       
>      #also tried class_eval str
>      #and just plain: eval str
>      #but none of these work!      
>   end
>
>end #class Client
>
>if $0 == __FILE__
>   require 'drb'
>   clientObj = Client.new
>   DRb.start_service('druby://0.0.0.0:9000',clientObj)
>   puts "Client started"
>   DRb.thread.join
>end
>####end Client.rb
>
>So I start Client.rb on a remote machine:
>remote> ruby Client.rb 
>
>Now, on the local machine I've got a file called Task.rb that defines a 
>Task class and tries to send it to the Client object running on remote:
>
>require 'drb'
>class Task
>   #include DRb::DRbUndumped
>   def initialize
>   end
>   
>   def run(*args)
>      puts "Task::Run - running #{args}"
>   end
>end
>
>if $0 == __FILE__
>   #require 'drb'
>   DRb.start_service()
>   client = DRbObject.new(nil,'druby://127.0.0.1:9000')
>   #read this file into a string and send it over:
>   requireString = ""
>   File.foreach($0) { |line|
>      requireString << line
>   }
>   client.remote_require(requireString)
>   puts client.run(Task.new, "ftp","xyz","abc")
>end
>#end Task.rb
>
>
>So I'm trying to send a Task object to the remote client and of course the 
>remote client knows nothing of Task objects (unless I put a 'require 
>"Task.rb" at the top of Client.rb and ensure that Task.rb is available on 
>tghe remote machine - but I don't want to do that because users might 
>define different classes of their own) so I added that 'remote_require' 
>method to the Client class.  I send the contents of Task.rb as a string to 
>the remote client's 'remote_require' method, but it doesn't work, I get:
>
>COULD_NOT_RUN
>
>printed on the local machine's stdout
>and:
>
>task type is: DRb::DRbUnknown
>
>printed on the remote machine's stdout which means that the remote client 
>object knows nothing about the Task class.  How can I change Client's 
>remote_require method to make this work?   
>