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 > Testing a library, how to auto, autoload
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Testing a library, how to auto, autoload

Réponse
 
LinkBack Outils de la discussion
Vieux 02/04/2008, 15h34   #1
goodieboy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Testing a library, how to auto, autoload

Hi,

I'm writing some tests for a library, and don't want to "require"
every single module/class. Anyone know if a quick way to set autoload
for all modules/classes for library?

Matt

  Réponse avec citation
Vieux 02/04/2008, 17h04   #2
Phlip
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Testing a library, how to auto, autoload

goodieboy wrote:
> Hi,
>
> I'm writing some tests for a library, and don't want to "require"
> every single module/class. Anyone know if a quick way to set autoload
> for all modules/classes for library?


Autoload is a Rails feature, and it's not strictly recommendable.

So the question turns to - why are your modules and classes hard to require? Do
you have a balanced set of .rb files, where each one requires the things it
uses? Can't you just pull all class of a module in with one top-level require?

--
Phlip
  Réponse avec citation
Vieux 02/04/2008, 18h21   #3
Joel VanderWerf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Testing a library, how to auto, autoload

goodieboy wrote:
> Hi,
>
> I'm writing some tests for a library, and don't want to "require"
> every single module/class. Anyone know if a quick way to set autoload
> for all modules/classes for library?


If you have some way of recognizing the names of your classes (such as a
regex), you could adapt the following:

if false
autoload :FileUtils, "fileutils"
else
class << Object
alias old_const_missing const_missing
def const_missing name
case name.to_sym
when :FileUtils; require "fileutils"; FileUtils
else
old_const_missing name
end
end
end
end

class A
def foo
p FileUtils
end
end

A.new.foo


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

  Réponse avec citation
Vieux 03/04/2008, 03h41   #4
Julian Leviston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Testing a library, how to auto, autoload

Grab the contents of the folder, then loop through requiring them all.

Julian.


Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO
(#2) OUT NOW!
http://sensei.zenunit.com/


On 03/04/2008, at 1:34 AM, goodieboy wrote:

> Hi,
>
> I'm writing some tests for a library, and don't want to "require"
> every single module/class. Anyone know if a quick way to set autoload
> for all modules/classes for library?
>
> Matt
>




  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 07h12.


É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,12215 seconds with 12 queries