Mimicking classpath and hierarchical packages ?

  • Thread starter Jean-Christophe Le Lann
  • Start date
J

Jean-Christophe Le Lann

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
 
R

Robert Klemme

2009/9/29 Jean-Christophe Le Lann said:
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
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top