ES <ruby-ml / magical-cat.org> writes:

> On 2/19/2005, "Lloyd Zusman" <ljz / asfast.com> wrote:
>
>> [ ... ]
>>
>>When my program encounters the "foo.module" file, I'd like it to do the
>>following:
>>
>>  - create a module called Foo (the name of the file with ".module"
>>    stripped off and the first letter capitalized) ... or maybe
>>    SomethingElse::Foo, to avoid collisions with existing packages
>>
>>  - do a load() of the "foo.module" file within the context of this
>>    newly created Foo module (or SomethingElse::Foo module)
>>
>>  - check to see if the #init method is now defined within the
>>    Foo module; if so, invoke that as a class method within the
>>    context of that module (i.e., as if it were invoked like
>>    Foo#init); this should cause the following message to
>>    print:
>>
>>      invoking #init within Foo
>>
>>What is the recommended way for accomplishing all this within Ruby?
>
> If you don't just want to write an actual module and then call its #init,
> you could do something like this. Somewhat pseudo:
>
> Thread.new do
>   if fname
>     mod = eval fname.capitalize
>     data = File.new(fname, 'r') do |f|
>              f.read
>            end
>     mod.module_eval data
>     mod.send :init, args
>     # ...
>   end
> end
>
> Or sumptin :)

Thanks.  This makes sense.

However, the "eval fname.capitalize" part doesn't create a new module,
and that's part of what is confusing me about all this.  Given a string
"Foo", what do I do to it in order to create a module object with that
name?


-- 
 Lloyd Zusman
 ljz / asfast.com
 God bless you.