|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 ful thread was the 1st one. (Saved me from asking a FAQ )-- Posted via http://www.ruby-forum.com/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 ful thread was the 1st one. > > (Saved me from asking a FAQ )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).n ew 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-forum.com/. |
|
![]() |
| Outils de la discussion | |
|
|