From: Austin Ziegler Date: 2002-11-08T08:47:47+09:00 Subject: Re: understanding modules/classes On Fri, 8 Nov 2002 05:49:14 +0900, Eric Schwartz wrote: > Austin Ziegler writes: >> On Thu, 7 Nov 2002 10:27:02 +0900, Eric Schwartz wrote: >>> Okay, that's not a problem. But I can't figure out how to export >>> classes from my module into the global namespace. In Perl, I'd >>> just add the functions to @EXPORT, and be done with it. Can this >>> be done in Ruby as well, or am I just thinking about it the >>> wrong way? Should I be creating my CGI executable in that same >>> module as well? Or am I just over-organizing here? >> Easily enough to do: > > > Okay, thanks to you and Gavin. One last question: is it good style > to put that in the class files? That is, do I put the 'include > Foo' in bar.rb, or in the file that 'require's it? I understand it > doesn't matter; I'm trying to get an idea for good Ruby style. It does matter where you put it, to a degree. "include" simply includes the methods and classes from a module into the current object scope. The "standard" object scope is (more or less) the Object object. Thus, when I do: include MIME::Types Then I have made it so that I can call the MIME::Types functions without any specifiers (although it may not be a good idea to do so). On the other hand, when I do: class Foo include MIME::Types end I have made it so that I can call the MIME::Types functions within the context of Foo, and would automagically gain Foo#[] behaving like MIME::Types::[]. More or less. I've probably goofed on some of the specifics, but the gist is there. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.11.07 at 18.42.38