Unrequiring a module

hello all, i'm using:

rb_require("file.rb");

to add a constant (class name) to my namespace in an embedded Ruby application. If i want to change the implementation details of that class without restart my application, how can i unrequire and re-require that file?

thanks very much

Iain Dooley

Strictly speaking, you can't. Well, you can't unrequire. However,
since all classes in Ruby are open, you can simply do the C-side
equivalent of Kernel.load.

-austin

···

On 8/27/05, Iain Dooley <idoo4002@mail.usyd.edu.au> wrote:

rb_require("file.rb");

to add a constant (class name) to my namespace in an embedded Ruby
application. If i want to change the implementation details of that
class without restart my application, how can i unrequire and re-require
that file?

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

hi Austin, thanks very much for your speedy response

Austin Ziegler wrote:

rb_require("file.rb");

to add a constant (class name) to my namespace in an embedded Ruby
application. If i want to change the implementation details of that
class without restart my application, how can i unrequire and re-require
that file?

Strictly speaking, you can't. Well, you can't unrequire. However,
since all classes in Ruby are open, you can simply do the C-side
equivalent of Kernel.load.

my worry with doing this would be that it would reload the 'Qt' extension that i'm including as well, which takes a while and is done on startup.

i've gotten around the problem by replacing my call to rb_require(filename) with:

     rb_load_file(filename);
     ruby_exec();

i read here:

http://www.rubycentral.com/book/tut_modules.html

that the difference between load and require in a Ruby script is that load will load the file everytime where require will do it only once. is there any reason why rb_load_file does not parse the document into the Ruby namespace? my ruby file looks like this:

class AssignSomeText < Qt::Object
     slots 'buttonClicked()'

     def setParent(parent)
         @parent = parent
     end

     def buttonClicked()
         @parent.child("textLabel1").text = @parent.child("lineEdit1").text
     end
end

if i simply load this file, then AssignSomeText is an undefined constant. if i rb_require() it then AssignSomeText is defined, but if i issue the require command again have changed some implementation details, those changes are not reflected unless i actually restart the application that the ruby interpreter is embedded in

cheers

iain

···

On 8/27/05, Iain Dooley <idoo4002@mail.usyd.edu.au> wrote:

     rb_load_file(filename);

class AssignSomeText < Qt::Object

first remove the constant AssignSomeText, then use rb_load_protect()

Guy Decoux

ts wrote:

"I" == Iain Dooley <idoo4002@mail.usyd.edu.au> writes:

> rb_load_file(filename);

> class AssignSomeText < Qt::Object

first remove the constant AssignSomeText, then use rb_load_protect()

i tried to find some way of remove a constant, but couldn't see one, what is the method?

cheers

iain

i tried to find some way of remove a constant, but couldn't see one,
what is the method?

Module#remove_const

rb_mod_remove_const() (in variable.c)

Guy Decoux