[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

requiring multiple files

rNuby

7/25/2007 2:14:00 PM

Hi all!
I was wonder how one goes about requireing multiple files.
I have the follow file structure:
Project/
run.rb
sub/
go.rb
require_me.rb

now in run.rb
require 'sub/go'
in go.rb
require 'require_me'

but when i execute run.rb, it says it can't find require_me.rb

what are the best ways to set up files and include then in ruby?

thankx!

2 Answers

Kyle Schmitt

7/25/2007 2:27:00 PM

0

run.rb is a directory higher than require_me.rb, so you're require line would be

require 'sub/require_me.rb'

This is also true for some of the standard library stuff. For
instance if you wanted the ftp library

require 'net/ftp'

Hope that helps,
Kyle

Alex Young

7/25/2007 2:31:00 PM

0

rNuby wrote:
> Hi all!
> I was wonder how one goes about requireing multiple files.
> I have the follow file structure:
> Project/
> run.rb
> sub/
> go.rb
> require_me.rb
>
> now in run.rb
> require 'sub/go'
> in go.rb
> require 'require_me'
>
> but when i execute run.rb, it says it can't find require_me.rb
try:

require 'sub/require_me'

> what are the best ways to set up files and include then in ruby?
I usually do something like this:

$app_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
$:.unshift($app_dir)


Assuming a layout like this:

bin/
launcher (<- here's where the above goes)
lib/
a.rb
b.rb

That way I know I can consistently use:

require 'lib/b'

from anywhere in the app.

--
Alex