fxri

Z

zeeman11

Hi,

I'm using fxri and I have required a ruby file as follows:

require "c:\myWork\motor.rb"

My question is, how do I reload this file when I make changes?

Thanks.
 
A

Austin Ziegler

Hi,

I'm using fxri and I have required a ruby file as follows:

require "c:\myWork\motor.rb"

1. You don't generally want to use Windows-style paths at all.
2. You don't generally want to use absolute paths at all.
3. You don't generally want to use the .rb extension with #require.
My question is, how do I reload this file when I make changes?

3. You want to #load the file, not #require the file. You MUST use the
rb extension with #load.

-austin
 
S

Stefano Crocco

Alle venerd=EC 2 marzo 2007, (e-mail address removed) ha scritto:
Hi,

I'm using fxri and I have required a ruby file as follows:

require "c:\myWork\motor.rb"

My question is, how do I reload this file when I make changes?

Thanks.

I assume you're speaking about the irb session embedded in fxri. If I'm wro=
ng,=20
my answer won't be very useful.

I think the cleanest way to reload a file is to use the load method:

load 'c:\myWork\motor.rb'

(note that with load you need to specify the extension).
Different from require, load doesn't check whether the file already is in $=
"=20
(the list of required files), although this is not explicitly said in the r=
i=20
documentation, and can't load C extensions.

Another way to reload the file should be to remove it from $" and use requi=
re.

In both cases, you must be careful. Suppose the file a.rb contains the=20
following:

=2D--File a.rb---

class C
def method1
"method1"
end

def method2
"method2"
end
end

In the interactive session, you do:

require 'a' #you could also do load 'a.rb'
c=3DC.new
c.method1
=3D> "method1"

c.method2
=3D> "method2"


Then you modify a.rb:

=2D--File a.rb modified---
class C

def method2
"method2"
end

end #you removed the definition of method1

You go back to the interactive session and type

c.method2
=3D> "method2"

c.method1 #you'd expect a NoMethodError, since the method has been removed.
=3D> "method1"

c1=3DC.new #create a new instance of C using the last definition

c1.method1
=3D>NoMethodError

The point is that loading the file again doesn't clear whatever it was defi=
ned=20
in it the first time it was loaded. I think (but I'm only guessing) that=20
loading for a second time a file which contains a class or a module looks a=
=20
bit like (but it's different from) reopening the class or module. For=20
instance, if in the modified a.rb you'd added the line=20

undef_method :method1

inside the definition of C, then calling c.method1 would have raised a=20
NoMethodError.


I hope all this helps

Stefano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fxri for windows? 4
how to use fxri 4
Like Fxri 2
How to detect what is running Ruby program? 4
fxri on OS X 0
fxri bug; where to report? 2
fxri newby question 1
fxri - gems - fxruby 3

Members online

Forum statistics

Threads
474,236
Messages
2,571,183
Members
47,818
Latest member
KazukoXea6

Latest Threads

Top