A question about require

Hello,

I was wondering what is the best way to “re-require” a file in ruby. In
my code, I have a function that looks like this:

def LoadAndExecute
require 'script_that_has_foo_in_it.rb’
foo
end

If I executre that function once, then modify the script_that_…rb and
re-execute the LoadAndExecute function without stopping everything, the
script file isn’t reaquired and foo re-execute the old code. I have
added the following line before require ‘…rb’

$".delete “script_that_…rb”

and it works fine but I want to make sure that it’s a valid way of doing
"re-require".

Thankx,
Ben.

load “script_that_has_foo_in_it.rb”

···

On Sun, Mar 02, 2003 at 02:31:54AM +0900, Ben Thomas wrote:

Hello,

I was wondering what is the best way to “re-require” a file in ruby. In
my code, I have a function that looks like this:

def LoadAndExecute
require ‘script_that_has_foo_in_it.rb’
foo
end

If I executre that function once, then modify the script_that_…rb and
re-execute the LoadAndExecute function without stopping everything, the
script file isn’t reaquired and foo re-execute the old code. I have
added the following line before require ‘…rb’

$".delete “script_that_…rb”

and it works fine but I want to make sure that it’s a valid way of doing
“re-require”.


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux: Where Don’t We Want To Go Today?
– Submitted by Pancrazio De Mauro, paraphrasing some well-known sales talk

Hi –

···

On Sun, 2 Mar 2003, Ben Thomas wrote:

Hello,

I was wondering what is the best way to “re-require” a file in ruby. In
my code, I have a function that looks like this:

load (as opposed to require)

David


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Ben Thomas wrote:

$".delete “script_that_…rb”

and it works fine but I want to make sure that it’s a valid way of doing
“re-require”.

Sounds like you would be better of with just using Kernel#load

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

Sorry I didn’t reply in the mailing list (a habit not to spam).

And that solution worked fine, thankx for the answer.

Ben.

Mauricio Fernández wrote:

···

On Sun, Mar 02, 2003 at 02:31:54AM +0900, Ben Thomas wrote:

Hello,

I was wondering what is the best way to “re-require” a file in ruby. In
my code, I have a function that looks like this:

def LoadAndExecute
require ‘script_that_has_foo_in_it.rb’
foo
end

If I executre that function once, then modify the script_that_…rb and
re-execute the LoadAndExecute function without stopping everything, the
script file isn’t reaquired and foo re-execute the old code. I have
added the following line before require ‘…rb’

$".delete “script_that_…rb”

and it works fine but I want to make sure that it’s a valid way of doing
“re-require”.

load “script_that_has_foo_in_it.rb”