Forum: Ruby it is possible to unload a class?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
sayoyo S. (Guest)
on 2006-01-24 21:00
(Received via mailing list)
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
Edward F. (Guest)
on 2006-01-24 22:13
(Received via mailing list)
On Wed, Jan 25, 2006 at 03:58:12AM +0900, removed_email_address@domain.invalid 
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.
Kelly Dwight F. (Guest)
on 2006-01-24 22:44
(Received via mailing list)
Is it possible to reload a class in irb?
Jules J. (Guest)
on 2006-01-24 23:05
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
Justin C. (Guest)
on 2006-01-24 23:11
(Received via mailing list)
Kelly Dwight F. wrote:
> Is it possible to reload a class in irb?
>
>
If it's from another file, you can use

irb>load 'someclass.rb'

instead of require.

-Justin
Logan C. (Guest)
on 2006-01-24 23:14
(Received via mailing list)
On Jan 24, 2006, at 4:05 PM, Jules J. 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/.
>

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.
Steffen Kern (Guest)
on 2006-01-25 16:04
(Received via mailing list)
Edward F. 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
Paul B. (Guest)
on 2006-01-26 18:06
(Received via mailing list)
On Wed, Jan 25, 2006 at 03:58:12AM +0900, removed_email_address@domain.invalid 
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?)

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

Paul
troyhen (Guest)
on 2006-01-26 18:15
(Received via mailing list)
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
This topic is locked and can not be replied to.