[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: class from string

Olie D.

11/4/2007 2:39:00 AM

Guest wrote:
> Thanks all for the responses -- it's obvious this is a FAQ, but just try
> and filter thru all the cruft with the words 'class' and 'string'!! -dan

FWIW, I searched the Ruby forum for

"class from string"

and this rather helpful thread was the 1st one.

(Saved me from asking a FAQ :D)
--
Posted via http://www.ruby-....

1 Answer

Olie D.

11/4/2007 5:27:00 PM

0

Olie D. wrote:
> Guest wrote:
>> Thanks all for the responses -- it's obvious this is a FAQ, but just try
>> and filter thru all the cruft with the words 'class' and 'string'!! -dan
>
> FWIW, I searched the Ruby forum for
>
> "class from string"
>
> and this rather helpful thread was the 1st one.
>
> (Saved me from asking a FAQ :D)

Bah! I was too quick on that -- now I'll probably end up asking FAQ'
<sigh>

I'm trying to read-in a folder full of "plug-ins" and call each of them,
in turn. Once I get the class-name, I do something like:

require "#{PLUG_IN_DIR}/#{one_plugin}"
plugin_class=Object.const_get(plugin_class_name).new
plugin_class.some_method

I *thought* that require worked a bit like the C pre-processor
"include", in that it would read and execute the named file at that
point, thereby defining my class and its methods. However, when I get
to the middle line, I get

uninitialized constant PluginClassName

Since rails is mistaking my class-name for a constant, I'm guessing that
require didn't execute the way I think it does, so my class-name isn't
initialized.

...Or maybe I've completely mis-diagnosed the problem.

At any rate, can someone offer a suggestion for how to read a folder
full of class-definition-files and, once at a time,

* Execute the class definition, so that my app knows about it
* Instantiate an instance of the class (I think we have this part,
above)
* Call a method on that class (should just be able to say
"a_class.a_method", right?)

Thanks!
--
Posted via http://www.ruby-....