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.
14b7344777a56ac9a1fad849f5d6da2a?d=identicon&s=25 sayoyo Sayoyo (sayoyo)
on 2006-01-24 20: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
036a1b88dafaab8ffd73a8b0a74b5b38?d=identicon&s=25 Edward Faulkner (Guest)
on 2006-01-24 21:13
(Received via mailing list)
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.
6559f9b9607a89074ea5e238d31ffbc2?d=identicon&s=25 Kelly Dwight Felkins (Guest)
on 2006-01-24 21:44
(Received via mailing list)
Is it possible to reload a class in irb?
71f1b6b2c3fd9af2e8c52618fb91caa6?d=identicon&s=25 Jules Jacobs (jules)
on 2006-01-24 22: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
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2006-01-24 22:11
(Received via mailing list)
Kelly Dwight Felkins 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
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-01-24 22:14
(Received via mailing list)
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/.
>

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.
0d5c93378d6c570a2bcf178e6c4b4d52?d=identicon&s=25 Steffen Kern (Guest)
on 2006-01-25 15:04
(Received via mailing list)
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
Fe6a008c1e3065327d1f1b007d8f1362?d=identicon&s=25 Paul Brannan (Guest)
on 2006-01-26 17:06
(Received via mailing list)
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?)

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

Paul
540d3f3166a3e0d9922504b043dd521a?d=identicon&s=25 troyhen (Guest)
on 2006-01-26 17: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.