Is there a way to 'unload' a script/module/class?

That won’t work since I need to instantiate a class within the loaded
file and pass arguments to it. :

···

-----Original Message-----
From: ts [mailto:decoux@moulon.inra.fr]
Sent: Thursday, March 06, 2003 10:42 AM
To: ruby-talk ML
Cc: ruby-talk@ruby-lang.org
Subject: Re: Is there a way to ‘unload’ a script/module/class ?

One of the things it can do is tell the Ruby script to load a
specific Ruby script (via ‘require’) and call a method of a known
class name that

use ‘load’ rather than ‘require’

Guy Decoux

That won't work since I need to instantiate a class within the loaded
file and pass arguments to it. :

I don't understand sorry, you don't want something like this ?

pigeon% cat b.rb
#!/usr/bin/ruby
["aaa", "bbb"].each do |mot|
   File.open("c.rb", "w") do |f|
      f.puts("class A; def aa() puts '#{mot}'; end; end")
   end
   load 'c.rb'
   A.new.aa
end
pigeon%

pigeon% b.rb
aaa
bbb
pigeon%

Guy Decoux

What if the loaded module is a “.so" or ".dll” file?
Will this still work?
Must I explicitly tell the ‘load’ the full name of the file
(or at least the extension)?
Thanks!
– Glenn Lewis

ts wrote:

···

“B” == Bennett, Patrick Patrick.Bennett@inin.com writes:

That won’t work since I need to instantiate a class within the loaded
file and pass arguments to it. :

I don’t understand sorry, you don’t want something like this ?

pigeon% cat b.rb
#!/usr/bin/ruby
[“aaa”, “bbb”].each do |mot|
File.open(“c.rb”, “w”) do |f|
f.puts(“class A; def aa() puts ‘#{mot}’; end; end”)
end
load ‘c.rb’
A.new.aa
end
pigeon%

pigeon% b.rb
aaa
bbb
pigeon%

Guy Decoux

Hi,

···

In message “Re: Is there a way to ‘unload’ a script/module/class ?” on 03/03/07, “Glenn M. Lewis” glenn@gmlewis.com writes:

What if the loaded module is a “.so" or ".dll” file?
Will this still work?

No. There’s no portable way to unload dynamic library.

						matz.

Hi Matz!

You are aware that Tcl does this, right?

At work, we develop C++ plugins for Tcl that get pulled in with its
‘package’ mechanism, and then unload them, recompile, and load them
back in again, all without having to restart the main application.
This works wonders for developers, especially when the startup time
of the application could be very large due to loading of large amounts
of data.

Granted, this is on Linux and HPUX... I'm not sure if Tcl

can handle this on other platforms.
– Glenn

Yukihiro Matsumoto wrote:

···

Hi,

In message “Re: Is there a way to ‘unload’ a script/module/class ?” > on 03/03/07, “Glenn M. Lewis” glenn@gmlewis.com writes:

What if the loaded module is a “.so" or ".dll” file?
Will this still work?

No. There’s no portable way to unload dynamic library.

  					matz.