[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how do I "unrequire" a file ?

Tuka Opaleye

12/5/2006 12:45:00 AM

Hi all,

In using migrate manually, I "require" the file containing the migration
and run it using console. I later decide to alter the same file on my
editor and try to run the migration again (after the code below) and
the changes are not effected.

I understand that when the migtation file is required a second time, it
is not loaded. how do I then unload it so that i can reload it with the
fresh changes ? Or is there a better way ?

TIA,
Tuka



>> require 'db/migrate/001_category.rb'
=> true
>> Category.down
== Category: reverting
========================================================
-- drop_table(:categories)
-> 0.4600s
== Category: reverted (0.4600s)
===============================================

=> nil
>> Category.up
== Category: migrating
========================================================
-- create_table(:categories)
-> 0.1700s
== Category: migrated (0.1700s)
===============================================

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

3 Answers

David Vallner

12/5/2006 1:32:00 AM

0

Tuka Opaleye wrote:
> Hi all,
>
> In using migrate manually, I "require" the file containing the migration
> and run it using console. I later decide to alter the same file on my
> editor and try to run the migration again (after the code below) and
> the changes are not effected.
>
> I understand that when the migtation file is required a second time, it
> is not loaded. how do I then unload it so that i can reload it with the
> fresh changes ? Or is there a better way ?
>

Use load (ri Kernel#load) instead of require. I -think- you need to use
the .rb with load as opposed to require, but I'm not sure.

David Vallner

Ken Bloom

12/5/2006 2:25:00 AM

0

On Tue, 05 Dec 2006 10:32:21 +0900, David Vallner wrote:

> Tuka Opaleye wrote:
>> Hi all,
>>
>> In using migrate manually, I "require" the file containing the migration
>> and run it using console. I later decide to alter the same file on my
>> editor and try to run the migration again (after the code below) and
>> the changes are not effected.
>>
>> I understand that when the migtation file is required a second time, it
>> is not loaded. how do I then unload it so that i can reload it with the
>> fresh changes ? Or is there a better way ?
>>
>
> Use load (ri Kernel#load) instead of require. I -think- you need to use
> the .rb with load as opposed to require, but I'm not sure.
>
> David Vallner

Yes, you do need to use the .rb extension with load.

require 'file'
#would become
load 'file.rb'

Note that there's no concept of unloading a file -- loading a file again
just extends the classes further, overriding any methods that have already
been defined.

This doesn't work out so well when alias_method metaprogramming
techniques come into play. You may also need to be sure not to use any
objects created from classes in the old version file.rb, but that will
depend on what you change.

--Ken

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Tuka Opaleye

12/5/2006 8:58:00 AM

0

Thanks,

your suggestions solved my problem.

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