[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Require within a module: path question

Drew Olson

3/6/2007 1:59:00 PM

All -

It seems to me that if I create a module, a.rb, and a script that
require's that module, b.rb, something interesting happens. In this
case, my a relies on other external files in the project, so I must
require these files within a.rb. However, I've noticed that because b
requires module a, all the require statements within the file a.rb must
be relative to b's location in the directory structure. Thus, when these
files are stored in different places, it becomes very confusing when
looking at file a.rb as to why the require statements don't seem to be
relative to that file. Is this intended functionality? Have I done
something stupid?

Thanks,
Drew

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

1 Answer

Brian Candler

3/6/2007 2:32:00 PM

0

On Tue, Mar 06, 2007 at 10:59:15PM +0900, Drew Olson wrote:
> It seems to me that if I create a module, a.rb, and a script that
> require's that module, b.rb, something interesting happens. In this
> case, my a relies on other external files in the project, so I must
> require these files within a.rb. However, I've noticed that because b
> requires module a, all the require statements within the file a.rb must
> be relative to b's location in the directory structure.

No - they just have to be relative to any of the directories in $: (the load
path array)

On my machine I get:

$ ruby1.8 -e 'puts $:'
/usr/local/lib/site_ruby/1.8
/usr/local/lib/site_ruby/1.8/i486-linux
/usr/local/lib/site_ruby/1.8/i386-linux
/usr/local/lib/site_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i486-linux
/usr/lib/ruby/1.8/i386-linux