Lionel Thiry
4/15/2005 9:09:00 PM
Hello.
I had the same problem in my beginnings.
But in fact, it is quite simple. Really simple when you realize that the main
and first purpose of modules is to extend classes. It is as if modules were just
class patches you can apply to the classes you want.
Then, now, using modules as namespaces for some classes or functions is just a
practical side effect. So practical that it is used all the time, but it is
still a side effect.
--
Lionel Thiry
Chris a écrit :
> <RubyNubyAlert>
> Doing my best to convert from Perl to Ruby, and mainly loving every
> minute of it.
>
> But I have a question about Modules... Why when I declare a Module, do
> I have to prefix all the routines in that module with the module name
> (or routines outside the module don't see it)? I don't get that?
> Isn't this kind of redundant? For instance, I can't do this:
>
> Module Foo
> def bar
> "bar"
> end
> end
>
> puts Foo.bar
>
> I have to do this:
>
> Module Foo
> def Foo.bar
> "bar"
> end
> end
>
> What's up with that? Seems redundant to me. (Oh, I already said
> that!) :-) But I thought I would ask. Maybe there is a good reason
> for this? Or, maybe there is a way around this?
> </RubyNubyA;ert>
>
> Thanks!
> -ceo
>