It is possible to unload a class?

Hi,

we can load a library, a class or a gem with the funtionc "require". If
I want to unload a library, a class or a gem, how can I do this, (or it
is possible?)

Thanks you very much

sayoyo

In general it's not possible.

I suppose you could try to hunt down and rebind every reference to the
classes/modules in the library, eventually allowing them to be garabge
collected. But I can't think of a practical reason to do that.

···

On Wed, Jan 25, 2006 at 03:58:12AM +0900, sayoyo@yahoo.com wrote:

we can load a library, a class or a gem with the funtionc "require". If
I want to unload a library, a class or a gem, how can I do this, (or it
is possible?)

See [ruby-talk:161691] and the following thread (in particular,
[ruby-talk:161865]).

Paul

···

On Wed, Jan 25, 2006 at 03:58:12AM +0900, sayoyo@yahoo.com wrote:

Hi,

we can load a library, a class or a gem with the funtionc "require". If
I want to unload a library, a class or a gem, how can I do this, (or it
is possible?)

Is it possible to reload a class in irb?

···

On 1/24/06, Edward Faulkner <ef@alum.mit.edu> wrote:

On Wed, Jan 25, 2006 at 03:58:12AM +0900, sayoyo@yahoo.com wrote:
> we can load a library, a class or a gem with the funtionc "require". If
> I want to unload a library, a class or a gem, how can I do this, (or it
> is possible?)

In general it's not possible.

I suppose you could try to hunt down and rebind every reference to the
classes/modules in the library, eventually allowing them to be garabge
collected. But I can't think of a practical reason to do that.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD1opAnhUz11p9MSARAkyeAKDSPS7oMmQuky/p9l3U8pNG21N2qwCgrcnp
eLWQ9EMWQ+RzdScCZ9SpLJQ=
=tmJb
-----END PGP SIGNATURE-----

Edward Faulkner schrieb:

I suppose you could try to hunt down and rebind every reference to the
classes/modules in the library, eventually allowing them to be garabge
collected. But I can't think of a practical reason to do that.

Well, there is at least one practical reason I can think of. Consider
a server running several services. Theses services may be started/loaded and stopped/unloaded during runtime. Thus, it would be really nice to get rid of classes or modules, which belong to an old service which was stopped.

Another aspect in this topic is: Is it possible to get rid of a mix-in which was introduced to a class? I mean, you have a class definition and
afterwards you add a mix-in to that class. At some point in the future, you don't need the functionality of the mix-in and want to get rid of it. Maybe it is possible with undef or something like that?

- Steffen

I haven't looked at the source to Webrick, but it seems to me that it
is doing this exact thing. For each request it somehow unloads and
reloads the entire application. If it didn't then your changes between
requests would not take effect. Please enlighten us on how this magic
happens.

Troy

You could try something with continuations? Go back to the original
state if you want to unload a library. You'll lose other things too,
unfortunately.

Jules

···

--
Posted via http://www.ruby-forum.com/.

Kelly Dwight Felkins wrote:

Is it possible to reload a class in irb?

If it's from another file, you can use

load 'someclass.rb'

instead of require.

-Justin

Continuations aren't that magical. They don't go back in time, just space as it were. IOW, if you can't do it with first class functions (possibly using CPS) (or catch/throw or exceptions (although exceptions for flow control is evil)), you probably can't do it with continuations either. Of course certain things may be easier to express with continuations. Continuations are really just glorified gotos.

···

On Jan 24, 2006, at 4:05 PM, Jules Jacobs wrote:

You could try something with continuations? Go back to the original
state if you want to unload a library. You'll lose other things too,
unfortunately.

Jules

-- Posted via http://www.ruby-forum.com/\.