PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Re: class from string
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: class from string

Réponse
 
LinkBack Outils de la discussion
Vieux 04/11/2007, 02h39   #1
ruby-forum@playnaked.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: class from string

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/.

  Réponse avec citation
Vieux 04/11/2007, 17h27   #2
ruby-forum@playnaked.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: class from string

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/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h39.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,22585 seconds with 10 queries