[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02101] Re: Scope violated by import via 'require'?

From: Clemens Hintze <c.hintze@...>
Date: 2000-03-23 08:58:30 UTC
List: ruby-talk #2101
Yukihiro Matsumoto writes:
> Hi,

Hi too,

> 
> In message "[ruby-talk:02084] Scope violated by import via 'require'?"
>     on 00/03/22, Clemens Hintze <c.hintze@gmx.net> writes:
> 
> |But if I put the definition of the inner module 'Bar' in a file on its
> |own called e.g. 'mBar.rb' and 'require' this file during module
> |definition of 'Foo', 'Bar' will be known both within 'Foo' and outside
> |of it:
> 
> Well, it's an expected behavior (at least I as expect it ;-)
> 
> require()/load() evaluates the contents of the file at the toplevel.

So does that mean it works as you intended? May I ask another
question? How can I achieve the goal described above? Is there any
way?

What is the reason for my desire? Sometimes I use helper
modules/classes to do some tasks for the 'real' module/class. Sometime
the helper is even a C extension. But of course, I would not like to
pollute the global namespace with the names of the helper
classes. That is because I am really lazy during inventing
names. Often one of my helper classes is called e.g. Parser ;-)

The helper classes are large enough to put them into an own
file. Furthermore I sometimes expect to rewrite them as C extension
for sake of performance. Put them into another file allows me to
simply replace the Ruby written extension with the C written one. No
change in the calling code necessary.

So let me sum up my question again: Is there any way that allows me to
put my module/class into an own file, and require it *into* another
module/class's namespace without polluting the toplevel namespace?

...

> module Bar is defined at the toplevel.  And in 1.5.x, `::' notation
> accesses the constants defined in superclasses too, which makes
> Foo::Bar valid.

That means, it is not in the module Foo, but will be found above in
Object, yes? Tricky, tricky! ;-)

> 
> 							matz.
> 

\cle

-- 
Clemens Hintze  mailto: c.hintze@gmx.net

In This Thread