# Mimicking classpath and hierarchical packages?

**URL:** <https://www.ruby-forum.com/t/mimicking-classpath-and-hierarchical-packages/176350>\
**Category:** Ruby\
**Created:** [September 29, 2009, 12:46pm UTC](https://www.ruby-forum.com/t/mimicking-classpath-and-hierarchical-packages/176350 "2009-09-29T12:46:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Christophe\_Le\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@Jean-Christophe\_Le\_S](https://www.ruby-forum.com/u/Jean-Christophe_Le_S)\
**Post date:** [September 29, 2009, 12:46pm UTC](https://www.ruby-forum.com/t/mimicking-classpath-and-hierarchical-packages/176350/1 "2009-09-29T12:46:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jean-Christophe\_Le\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@Jean-Christophe\_Le\_S](https://www.ruby-forum.com/u/Jean-Christophe_Le_S)\
**Post date:** [September 29, 2009, 1:43pm UTC](https://www.ruby-forum.com/t/mimicking-classpath-and-hierarchical-packages/176350/2 "2009-09-29T13:43:13Z")

</div>

2009/9/29 Jean-Christophe Le Lann [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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
