Re: include problem

Shugo Maeda <[email protected]> Wed, 13 Oct 2004 01:11:51 +0900
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
Hi,
Sorry to be late.

[email protected] wrote:
> We run several virtual hosts on one machine, each has a structure like 
> this:

Do you run virtual hosts on same Apache processes?
If so the ruby interpreter is shared by all virtual hosts.
This may cause problems.

> file: /rb/tools.rb
> 
>   module name_of_host  # to avoid namespace collisions
>       def a ()
>           # ...
>       end
>   end
> 
> file: /subdir/rb/tools.rb
> 
>   module name_of_host_subdir
>       require '../rb/tools.rb'
>       include name_of_host
>       def b ()
>           # ...
>       end
>   end
> 
> file: /subdir/language/index.rhtml
> 
>   <%
>   require '../rb/tools.rb'
>   include name_of_host_subdir
>   a()
>   b()
>   %>

`require' loads same library only once, so /rb/tools.rb will not be loaded.

The error message on my environment (mod_ruby/1.2.4 
Ruby/1.8.2(2004-08-24)) is here:

[Wed Oct 13 01:08:09 2004] [error] mod_ruby: error in ruby
[Wed Oct 13 01:08:09 2004] [error] mod_ruby: ../rb/tools.rb:3: 
uninitialized constant Bar::Foo (NameError)
[Wed Oct 13 01:08:09 2004] [error] mod_ruby:   from 
/home/shugo/public_html/test/subdir/language/index.rhtml:2:in `require'
[Wed Oct 13 01:08:09 2004] [error] mod_ruby:   from 
/home/shugo/public_html/test/subdir/language/index.rhtml:2
[Wed Oct 13 01:08:09 2004] [error] mod_ruby:   from (eval):0

(I change name_of_host to Foo, name_of_host_subdir to Bar.)

Shugo