Mimicking classpath and hierarchical packages?

Hi,

I’d like to have your advices concerning these points : how to to mimick
the java notions of classpath and of hierarchical packages, in ruby, as
close as possible ?

Is there a standard and clean way of doing this ?

Thanks !
Jean-Christophe

2009/9/29 Jean-Christophe Le Lann [email protected]:

I’d like to have your advices concerning these points : how to to mimick
the java notions of classpath and of hierarchical packages, in ruby, as
close as possible ?

Is there a standard and clean way of doing this ?

“Classpath” is stored in $: and $LOAD_PATH (they point to the same
object). Shell variable is $RUBYLIB.

Typically files are named similar to their content, e.g.

file mypro.rb

module MyPro
end

optional:

require ‘mypro/c1’

file mypro/c1.rb

require ‘mypro’

module MyPro
class C1
end
end

etc.

Use via require ‘mypro/c1’ or require ‘mypro’.

Alternative:

file mypro.rb

module MyPro
autoload ‘C1’, ‘c1’
end

file mypro/c1.rb

require ‘mypro’

module MyPro
class C1
end
end

Use via require ‘mypro/c1’ or require ‘mypro’.

You can see this in various standard libraries as well. You can look
at REXML for example.

Kind regards

robert