[#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:02084] Scope violated by import via 'require'?

From: Clemens Hintze <c.hintze@...>
Date: 2000-03-22 19:52:22 UTC
List: ruby-talk #2084
Hi,

I have following found. If I define one module *in* another one, the
innermost is only accessible via the outer one. That means:

   $ ruby -v 
   ruby 1.5.3 (2000-03-15) [i586-linux] 

   $ ruby
   module Foo
     module Bar
     end
   end

   p Foo::Bar  # This would be ok!
   p Bar       # This of course not, as Bar is part of Foo.
   ^D
   Foo::Bar    # Ok!
   -:7: uninitialized constant Bar (NameError)  # Yep!

This behavior as expected (at least as *I* expect it ;-)

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:

   $ cat mBar.rb
   module Bar
   end

   $ ruby
   module Foo
     require "mBar"
   end
   
   p Foo::Bar   # This should be ok!
   p Bar        # And this should be wrong, shouldn't it?
   ^D
   Bar          # Ok :-)
   Bar          # Oops! :-(

I would like to know, if this is a bug or a feature? If it is a
feature, does that mean I can count of it? If it is a bug, I have
another problem I would tell you then!

Ciao,
\cle

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

In This Thread

Prev Next